veza/apps/web/src/components/auth/ProtectedRoute.tsx

20 lines
507 B
TypeScript
Raw Normal View History

import { Navigate } from 'react-router-dom';
import { useAuth } from '@/features/auth/hooks/useAuth';
interface ProtectedRouteProps {
children: React.ReactNode;
}
/**
* Composant de protection des routes authentifiées.
* Redirige vers /login si l'utilisateur n'est pas authentifié.
*/
export function ProtectedRoute({ children }: ProtectedRouteProps) {
const { isAuthenticated } = useAuth();
if (!isAuthenticated) {
return <Navigate to="/login" replace />;
}
return <>{children}</>;
}