/** * Protected Route - PRODUCTION READY * Uses shared AuthContext - no independent session checks */ import { Navigate, useLocation } from 'react-router-dom'; import { useAuth } from '../contexts/AuthContext'; interface Props { children: React.ReactNode; requireAdmin?: boolean; } export default function ProtectedRoute({ children, requireAdmin = false }: Props) { const location = useLocation(); const { isAuthenticated, loading, user } = useAuth(); // Show loading while AuthContext is checking session if (loading) { return (
); } // Not authenticated - redirect to login if (!isAuthenticated) { return ; } // Admin check if required if (requireAdmin) { const role = user?.user_metadata?.role; const isAdmin = role === 'admin' || role === 'super_admin'; if (!isAdmin) { return (

Access Denied

Go to Dashboard
); } } // Authenticated - render content return <>{children}; }