19 lines
398 B
TypeScript
19 lines
398 B
TypeScript
import { Navigate, Outlet } from 'react-router-dom';
|
|
import { useAuth } from '../context/AuthContext';
|
|
|
|
const ProtectedRoute = () => {
|
|
const { user, loading } = useAuth();
|
|
|
|
if (loading) {
|
|
return <div className="loading-state">Vérification de la session...</div>;
|
|
}
|
|
|
|
if (!user) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
|
|
return <Outlet />;
|
|
};
|
|
|
|
export default ProtectedRoute;
|