import { Navigate, useLocation } from 'react-router-dom'; import { useAuth } from '@/hooks/useAuth'; import { Loader2 } from 'lucide-react'; interface ProtectedRouteProps { children: React.ReactNode; adminOnly?: boolean; } export default function ProtectedRoute({ children, adminOnly = false }: ProtectedRouteProps) { const { isAuthenticated, isLoading, user } = useAuth(); const location = useLocation(); if (isLoading) { return (
); } if (!isAuthenticated) { return ; } if (adminOnly && user?.role !== 'admin') { return ; } return <>{children}; }