import { cookies, headers } from "next/headers"; import { redirect } from "next/navigation"; import type { ReactNode } from "react"; import { AdminShell } from "@/components/admin/shell"; import { ADMIN_COOKIE } from "@/lib/admin-api"; export const dynamic = "force-dynamic"; /** * Auth guard for every console page: no `dci_admin` cookie → /admin/login?next=… * The token itself is validated by the API on each proxied call (a stale cookie yields 401 → the client hook * redirects to the login page with reason=expired). */ export default async function AdminShellLayout({ children }: { children: ReactNode }) { const jar = await cookies(); if (!jar.get(ADMIN_COOKIE)?.value) { const h = await headers(); const next = h.get("x-invoke-path") ?? h.get("next-url") ?? "/admin"; redirect(`/admin/login?next=${encodeURIComponent(next.startsWith("/admin") ? next : "/admin")}`); } return {children}; }