File size: 1,011 Bytes
815c966
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bfb06d5
 
 
 
 
 
 
815c966
 
 
 
 
 
 
 
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
35
36
37
38
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",
    },
  });
}