File size: 975 Bytes
815c966
69698fb
815c966
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bfb06d5
815c966
bfb06d5
 
 
 
69698fb
815c966
bfb06d5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}