import { Navigate, Outlet, useLocation } from 'react-router-dom'; import { useAuth } from '../context/AuthContext'; import { SpinnerIcon } from './icons'; function FullScreenSpinner({ label }: { label?: string }) { return (
{label && {label}}
); } // Forces a session. Sends to /auth otherwise. export function RequireAuth() { const { session, ready } = useAuth(); const loc = useLocation(); if (!ready) return ; if (!session) return ; return ; } // Forces a usable per-user encrypted key blob on this install. Sends to // /device (the setup/unlock page) when the blob is missing or locked. export function RequireDevice() { const { userKeyState } = useAuth(); if (userKeyState.status === 'loading') return ; if (userKeyState.status === 'needs-setup' || userKeyState.status === 'needs-unlock') { return ; } return ; } // Admin-only route gate. Non-admins bounce to /chats — RLS still enforces // server-side, this is purely a UX shortcut. export function RequireAdmin() { const { profile } = useAuth(); if (profile && !profile.isAdmin) return ; return ; }