/** * Typed API client for the FamilySync backend. * * credentials: 'include' is required so the OIDC session cookie is sent with * every cross-origin request (Vite dev proxy routes to :3000; production is * same-origin via Pangolin). * * 401 responses mean the session has expired — the browser will follow the * 302 redirect to Authelia on the next API call automatically (full-page nav). */ export interface MeUser { id: number displayName: string | null color: string } export interface MeResponse { user: MeUser } export async function fetchMe(): Promise { const res = await fetch('/api/me', { credentials: 'include', }) if (!res.ok) { // 302 → browser follows redirect to Authelia automatically. // For 4xx/5xx, throw so React Query can surface the error. throw new Error(`GET /api/me failed: ${res.status}`) } return res.json() as Promise }