20 lines
508 B
TypeScript
20 lines
508 B
TypeScript
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}</>;
|
|
}
|