v1.0
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { Navigate, useLocation } from 'react-router-dom';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
|
||||
export default function ProtectedRoute({ children }) {
|
||||
const { isAdmin } = useAuth();
|
||||
const location = useLocation();
|
||||
|
||||
if (!isAdmin) {
|
||||
return <Navigate to={`/login?next=${encodeURIComponent(location.pathname)}`} replace />;
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
Reference in New Issue
Block a user