hamba-ho's picture
feat: Finalisation de l'application full stack avec Docker Compose
83b4232
raw
history blame contribute delete
416 Bytes
import React from 'react';
import { Navigate } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
const ProtectedRoute = ({ children, roles }) => {
const { user } = useAuth();
if (!user) {
return <Navigate to="/login" />;
}
if (roles && !roles.includes(user.role)) {
return <Navigate to="/" />;
}
return children;
};
export default ProtectedRoute;