feat(F-048): completed feature

This commit is contained in:
chattie
2026-08-19 07:17:14 +02:00
parent 8ee1938af9
commit 835ab66eda
187 changed files with 12361 additions and 1065 deletions

View File

@@ -3,9 +3,10 @@ import { NextRequest, NextResponse } from 'next/server';
const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://127.0.0.1:3000';
/**
* Strip the Secure flag from the backend's Set-Cookie so the browser
* (which connects over HTTP) actually stores the session cookie.
* Also drop SameSite=Lax to avoid browser restrictions.
* FIX-14: admin panel auth now goes through the backoffice auth endpoint,
* which sets a separate `backoffice_session` cookie (independent of the
* storefront `mdv_session`). This keeps the physical separation between
* backoffice users and storefront customers.
*/
function makeLocalhostCompatible(cookie: string): string {
return cookie
@@ -19,7 +20,7 @@ export async function POST(req: NextRequest) {
const body = await req.json();
const { email, password } = body;
const backendRes = await fetch(`${API}/auth/login`, {
const backendRes = await fetch(`${API}/backoffice/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
@@ -43,4 +44,4 @@ export async function POST(req: NextRequest) {
{ status: 500 },
);
}
}
}

View File

@@ -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;
}

View File

@@ -2,10 +2,11 @@ import { NextRequest, NextResponse } from 'next/server';
const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://127.0.0.1:3000';
/** FIX-14: admin panel auth now resolves through the backoffice endpoint. */
export async function GET(req: NextRequest) {
const cookies = req.headers.get('cookie') ?? '';
try {
const backendRes = await fetch(`${API}/auth/me`, {
const backendRes = await fetch(`${API}/backoffice/auth/me`, {
headers: { Cookie: cookies },
});
if (!backendRes.ok) return NextResponse.json({ user: null });
@@ -13,4 +14,4 @@ export async function GET(req: NextRequest) {
} catch {
return NextResponse.json({ user: null });
}
}
}