Luminaria / frontend /app /api /admin /me /route.ts
senlinyy's picture
fix: fix cookie issue
bfb06d5
Raw
History Blame Contribute Delete
1.01 kB
import { type NextRequest, NextResponse } from "next/server";
import { backendUrl } from "@/lib/backend-url";
export const dynamic = "force-dynamic";
export const runtime = "nodejs";
export async function GET(request: NextRequest) {
let response: Response;
try {
response = await fetch(`${backendUrl()}/admin/me`, {
headers: {
cookie: request.headers.get("cookie") ?? "",
},
cache: "no-store",
});
} catch {
return NextResponse.json(
{ detail: "Could not reach the backend admin session service." },
{ status: 502 }
);
}
if (response.status === 401 || response.status === 403) {
return NextResponse.json(
{ authenticated: false },
{ status: 200, headers: { "cache-control": "no-store" } }
);
}
return new NextResponse(await response.text(), {
status: response.status,
headers: {
"content-type": response.headers.get("content-type") ?? "application/json",
"cache-control": "no-store",
},
});
}