import { NextResponse, type NextRequest } from "next/server"; /** Leaves the preview: an admin goes back to editing, someone with a shared link to the live site. */ export function GET(request: NextRequest) { const admin = request.cookies.get("ccw_preview")?.value === "admin"; const trying = !!request.cookies.get("ccw_preview_template")?.value; const to = admin ? (request.nextUrl.searchParams.get("published") ? "/admin/publish" : trying ? "/admin/template" : "/admin") : "/"; const res = NextResponse.redirect(new URL(to, request.url), 303); res.cookies.delete("ccw_preview"); res.cookies.delete("ccw_preview_template"); return res; }