diff --git a/components/auth/protected-route.tsx b/components/auth/protected-route.tsx index 1225cd0..6fae5d2 100644 --- a/components/auth/protected-route.tsx +++ b/components/auth/protected-route.tsx @@ -15,32 +15,27 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) { const [isChecking, setIsChecking] = useState(true); useEffect(() => { - // If still loading auth state, wait - if (isLoading) { - return; - } + if (isLoading) return; - // Check if user is authenticated const isAuthenticated = !!(token || user); - + if (isAuthenticated) { setIsChecking(false); } else { - // Only redirect if we're not already on the auth page - if (!pathname.includes('/auth/login')) { - console.log('Not authenticated - redirecting to auth'); - // Use replace: false to allow back button to work properly + // Redirect logic for unauthenticated users + if (!pathname.includes("/auth/login")) { + console.log("Not authenticated - redirecting to login"); router.push("/auth/login"); } setIsChecking(false); } }, [user, isLoading, token, router, pathname]); - // Show loading while checking authentication + // Show loading spinner while checking auth if (isLoading || isChecking) { return (