// Pure, edge-safe route-guard decision logic, shared by middleware. // Returns the path to redirect to, or null to allow the request. export const PUBLIC_PATHS = new Set([ "/login", "/register", "/register/verify", "/forgot-password", "/reset-password", ]); export function isPublicPath(pathname: string): boolean { return PUBLIC_PATHS.has(pathname); } export interface SessionState { present: boolean; resetRequired?: boolean; phoneVerifyRequired?: boolean; } export function guardDecision(pathname: string, session: SessionState | null): string | null { const present = !!session?.present; if (!present) { return isPublicPath(pathname) ? null : "/login"; } // Authenticated: enforce password reset before granting app access. if (session?.resetRequired && pathname !== "/reset-password") { return "/reset-password"; } if (session?.phoneVerifyRequired && !session.resetRequired && pathname !== "/register/verify") { return "/register/verify"; } return null; }