import { useEffect, useRef } from "react"; import { useLocation } from "wouter"; import { useAuth } from "@/lib/auth"; interface ProtectedRouteProps { children: React.ReactNode; } export function ProtectedRoute({ children }: ProtectedRouteProps) { const { isAuthenticated, isLoading, user } = useAuth(); const [, setLocation] = useLocation(); const wasAuthenticated = useRef(false); if (isAuthenticated) { wasAuthenticated.current = true; } useEffect(() => { if (!isLoading && !isAuthenticated) { setLocation("/login"); } }, [isLoading, isAuthenticated, setLocation]); if (isLoading) { if (wasAuthenticated.current || user) { return <>{children}>; } return (