35 lines
935 B
TypeScript
35 lines
935 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { cookies } from "next/headers";
|
|
import { COOKIE_ACCESS } from "@/lib/auth-cookies";
|
|
|
|
const BASE_URL =
|
|
process.env.BASE_API_URL ?? process.env.NEXT_PUBLIC_BASE_API_URL ?? "http://127.0.0.1:8080";
|
|
|
|
export async function GET() {
|
|
const cookieStore = await cookies();
|
|
const accessToken = cookieStore.get(COOKIE_ACCESS)?.value;
|
|
|
|
if (!accessToken) {
|
|
return NextResponse.json({ loggedIn: false });
|
|
}
|
|
|
|
try {
|
|
const res = await fetch(`${BASE_URL}/api/v1/auth/me`, {
|
|
headers: {
|
|
accept: "application/json",
|
|
Authorization: `Bearer ${accessToken}`,
|
|
},
|
|
});
|
|
if (!res.ok) {
|
|
return NextResponse.json({ loggedIn: false });
|
|
}
|
|
const data = await res.json();
|
|
return NextResponse.json({
|
|
loggedIn: true,
|
|
user: (data as { user?: unknown }).user,
|
|
});
|
|
} catch {
|
|
return NextResponse.json({ loggedIn: false });
|
|
}
|
|
}
|