import 'server-only'; import { cookies } from 'next/headers'; /** * Admin session = the admin token itself, stored in an httpOnly cookie set by the login server action. * It is read only on the server (`cookies()`), forwarded as `x-aia-admin-token`, and never rendered. */ export const ADMIN_COOKIE = 'aia-admin'; export const ADMIN_COOKIE_MAX_AGE = 12 * 3600; // 12 h export async function getAdminToken(): Promise { const store = await cookies(); const v = store.get(ADMIN_COOKIE)?.value; return v && v.length > 0 ? v : null; } export async function setAdminToken(token: string): Promise { const store = await cookies(); store.set(ADMIN_COOKIE, token, { httpOnly: true, sameSite: 'lax', secure: process.env.NODE_ENV === 'production', path: '/admin', maxAge: ADMIN_COOKIE_MAX_AGE, }); } export async function clearAdminToken(): Promise { const store = await cookies(); store.set(ADMIN_COOKIE, '', { httpOnly: true, sameSite: 'lax', secure: process.env.NODE_ENV === 'production', path: '/admin', maxAge: 0 }); }