import { Navigate, useLocation } from 'react-router-dom'; import { useAuth } from '@/contexts/AuthContext'; interface ProtectedRouteProps { children: React.ReactNode; } export default function ProtectedRoute({ children }: ProtectedRouteProps) { const { isAuthenticated, isLoading } = useAuth(); const location = useLocation(); console.log('ProtectedRoute check:', { isAuthenticated, isLoading, path: location.pathname }); if (isLoading) { // Show a loading spinner while authentication state is being determined return (
); } if (!isAuthenticated) { console.log('Not authenticated, redirecting to login'); // Redirect to the login page, but save the current location they were trying to access return ; } console.log('User is authenticated, showing protected content'); return <>{children}; }