11 lines
361 B
TypeScript
11 lines
361 B
TypeScript
import { Navigate, Outlet } from 'react-router-dom';
|
|
import { useAuth } from '../auth/AuthContext';
|
|
import { Spinner } from './Spinner';
|
|
|
|
export function ProtectedRoute() {
|
|
const { user, loading } = useAuth();
|
|
if (loading) return <Spinner label="Checking your credentials…" />;
|
|
if (!user) return <Navigate to="/login" replace />;
|
|
return <Outlet />;
|
|
}
|