hasari-api / apps /desktop /src /components /ProtectedRoute.tsx
erdoganpeker's picture
v0.3.0 β€” multimodal vehicle damage MVP
e327f0d
/**
* Route guard β€” redirects to /login when no auth user is present.
* Renders nothing until the auth context has finished bootstrapping (avoids login-flash).
*/
import { ReactNode } from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import { useAuth } from '@/contexts/AuthContext';
export function ProtectedRoute({ children }: { children: ReactNode }) {
const { user, ready } = useAuth();
const loc = useLocation();
if (!ready) return null;
if (!user) return <Navigate to="/login" replace state={{ from: loc.pathname }} />;
return <>{children}</>;
}
export default ProtectedRoute;