feat(F-048): completed feature
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://127.0.0.1:3000';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
/** FIX-14: logout hits the backoffice endpoint and clears backoffice_session. */
|
||||
export async function POST() {
|
||||
try {
|
||||
const cookies = req.headers.get('cookie') ?? '';
|
||||
await fetch(`${API}/auth/logout`, {
|
||||
const { cookies } = await import('next/headers');
|
||||
const token = (await cookies()).get('backoffice_session')?.value;
|
||||
await fetch(`${API}/backoffice/auth/logout`, {
|
||||
method: 'POST',
|
||||
headers: { Cookie: cookies },
|
||||
headers: token ? { Cookie: `backoffice_session=${token}` } : {},
|
||||
});
|
||||
} catch {
|
||||
// Best-effort
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
const response = NextResponse.json({ ok: true });
|
||||
response.cookies.delete('mdv_session');
|
||||
return response;
|
||||
}
|
||||
const res = NextResponse.json({ ok: true }, { status: 200 });
|
||||
res.cookies.set('backoffice_session', '', { path: '/', maxAge: 0 });
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user