Spaces:
Sleeping
Sleeping
File size: 622 Bytes
e327f0d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /**
* 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;
|