import { NextResponse, type NextRequest } from "next/server"; import { getToken, clearSession } from "@/app/lib/server/session"; import { callMobileApi } from "@/app/lib/server/mobileApi"; import { clientContextHeaders } from "@/app/lib/server/clientContext"; // POST → /api/admin/auth/logout, best-effort: the cookie is cleared // regardless of whether the upstream call succeeds, so the browser is always // signed out locally even if the upstream token invalidation fails. // The real client's IP/user-agent are forwarded so mobile-api can record the // LOGOUT row in the login_audit trail. export async function POST(req: NextRequest) { const token = await getToken(); if (token) { await callMobileApi("/api/admin/auth/logout", { method: "POST", token, headers: clientContextHeaders(req), }); } await clearSession(); return NextResponse.json({ ok: true }); }