.
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
import { Navigate } from 'react-router-dom';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { CircularProgress, Box } from '@mui/material';
|
||||
|
||||
export default function PrivateRoute({ children, allowedRoles }) {
|
||||
const { isAuthenticated, role } = useAuth();
|
||||
const { isAuthenticated, role, loading } = useAuth();
|
||||
|
||||
if (loading) return (
|
||||
<Box display="flex" justifyContent="center" alignItems="center" minHeight="100vh">
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
);
|
||||
|
||||
if (!isAuthenticated) return <Navigate to="/login" replace />;
|
||||
if (allowedRoles && !allowedRoles.includes(role)) return <Navigate to="/unauthorized" replace />;
|
||||
|
||||
Reference in New Issue
Block a user