import { cookies } from "next/headers"; import { getMe, safe } from "./api"; import { AUTH_TOKEN_COOKIE } from "./config"; import { reassembleChunkedCookie } from "./authUser"; import type { AuthUser } from "./types"; export { displayName, isAdmin } from "./authUser"; // Server-side "am I logged in" check for the header/account menu. Reads the // cookie the customer dashboard writes on login (see AUTH_TOKEN_COOKIE in // config.ts and AI_PROMPT.md "Shared login") — this storefront never issues // it. Resolves to null whenever the cookie is absent or /auth/me fails — // never throws, so a missing session degrades to the anonymous view. export async function getSession(): Promise { const store = await cookies(); const raw = reassembleChunkedCookie((name) => store.get(name)?.value, AUTH_TOKEN_COOKIE); if (!raw) return null; const token = decodeURIComponent(raw); const result = await safe(getMe(token), null); return result?.user ?? null; }