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}/backoffice/auth/me`, {
      headers: { Cookie: cookies },
    });
    if (!backendRes.ok) return NextResponse.json({ user: null });
    return NextResponse.json(await backendRes.json());
  } catch {
    return NextResponse.json({ user: null });
  }
}