export type Portal = 'admin' | 'client'; export type SessionUser = { id: string; tenantId?: string | null; tenantName?: string | null; username: string; email?: string | null; phone?: string | null; displayName: string; roles: string[]; }; export type LoginSession = { accessToken: string; tokenType: string; portal: Portal; user: SessionUser; }; const sessionKey = 'cmpp-auth-session'; export function readSession(): LoginSession | null { try { const raw = window.localStorage.getItem(sessionKey); return raw ? JSON.parse(raw) as LoginSession : null; } catch { return null; } } export function writeSession(session: LoginSession) { window.localStorage.setItem(sessionKey, JSON.stringify(session)); } export function clearSession() { window.localStorage.removeItem(sessionKey); } export function getSessionTenantId() { return readSession()?.user.tenantId ?? undefined; }