Initial commit
This commit is contained in:
11
src/pages/RoleProtectedRoute.jsx
Normal file
11
src/pages/RoleProtectedRoute.jsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Navigate } from 'react-router-dom';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
|
||||
const RoleProtectedRoute = ({ children, allowedRoles }) => {
|
||||
const { user } = useAuth();
|
||||
if (!user) return <Navigate to="/login" />;
|
||||
if (!allowedRoles.includes(user.role)) return <Navigate to="/login" />;
|
||||
return children;
|
||||
};
|
||||
|
||||
export default RoleProtectedRoute;
|
||||
Reference in New Issue
Block a user