14 lines
369 B
React
14 lines
369 B
React
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;
|
|
}
|