You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
928 B
43 lines
928 B
import { NextResponse } from "next/server";
|
|
import { cookies } from "next/headers";
|
|
import {
|
|
SESSION_COOKIE_NAME,
|
|
popiartFetchEnvelope,
|
|
} from "@/lib/popiart-api";
|
|
|
|
export async function POST() {
|
|
const cookieStore = await cookies();
|
|
const token = cookieStore.get(SESSION_COOKIE_NAME)?.value;
|
|
|
|
try {
|
|
if (token) {
|
|
await popiartFetchEnvelope<{ logged_out: boolean }>("/auth/logout", {
|
|
method: "POST",
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
});
|
|
}
|
|
} catch {
|
|
// Clear the local session even if the upstream logout call fails.
|
|
}
|
|
|
|
const response = NextResponse.json({
|
|
ok: true,
|
|
data: {
|
|
logged_out: true,
|
|
},
|
|
});
|
|
|
|
response.cookies.set({
|
|
name: SESSION_COOKIE_NAME,
|
|
value: "",
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
secure: process.env.NODE_ENV === "production",
|
|
path: "/",
|
|
maxAge: 0,
|
|
});
|
|
|
|
return response;
|
|
}
|
|
|