This commit is contained in:
2026-04-17 20:16:51 +02:00
parent c3c05e8af4
commit adb797e709
3 changed files with 47 additions and 39 deletions

View File

@@ -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 />;