senlinyy's picture
fix: fix cookie
69698fb
Raw
History Blame Contribute Delete
975 Bytes
import { type NextRequest, NextResponse } from "next/server";
import { clearAdminSessionCookie } from "@/lib/admin-session-cookie";
import { backendUrl } from "@/lib/backend-url";
export const dynamic = "force-dynamic";
export const runtime = "nodejs";
export async function POST(request: NextRequest) {
let response: Response;
try {
response = await fetch(`${backendUrl()}/admin/logout`, {
method: "POST",
headers: {
cookie: request.headers.get("cookie") ?? "",
},
});
} catch {
return NextResponse.json(
{ detail: "Could not reach the backend admin logout service." },
{ status: 502 }
);
}
const nextResponse = new NextResponse(await response.text(), {
status: response.status,
headers: {
"content-type": response.headers.get("content-type") ?? "application/json",
},
});
clearAdminSessionCookie(nextResponse.headers, request.nextUrl.protocol === "https:");
return nextResponse;
}