From b72aa3e8ca4934c6e45fed6e4d23f4abc66bd1e1 Mon Sep 17 00:00:00 2001 From: yangdx Date: Sun, 23 Mar 2025 01:16:53 +0800 Subject: [PATCH] Prevent login page show up when on auth is needed --- lightrag_webui/src/AppRouter.tsx | 1 + lightrag_webui/src/features/LoginPage.tsx | 19 ++++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lightrag_webui/src/AppRouter.tsx b/lightrag_webui/src/AppRouter.tsx index 1d957174..f0a07ad3 100644 --- a/lightrag_webui/src/AppRouter.tsx +++ b/lightrag_webui/src/AppRouter.tsx @@ -49,6 +49,7 @@ const AppContent = () => { return () => { isMounted = false; + setInitializing(false) } }, [isAuthenticated]) diff --git a/lightrag_webui/src/features/LoginPage.tsx b/lightrag_webui/src/features/LoginPage.tsx index 645e8fe9..29217594 100644 --- a/lightrag_webui/src/features/LoginPage.tsx +++ b/lightrag_webui/src/features/LoginPage.tsx @@ -31,7 +31,6 @@ const LoginPage = () => { const checkAuthConfig = async () => { // Prevent duplicate calls in Vite dev mode if (authCheckRef.current) { - if (isMounted) setCheckingAuth(false); return; } authCheckRef.current = true; @@ -46,20 +45,11 @@ const LoginPage = () => { // Check auth status const status = await getAuthStatus() - // Set checkingAuth to false immediately after getAuthStatus - // This allows the login page to render while other processing continues - if (isMounted) { - setCheckingAuth(false); - } - // Set session flag for version check to avoid duplicate checks in App component - if (isMounted && (status.core_version || status.api_version)) { + if (status.core_version || status.api_version) { sessionStorage.setItem('VERSION_CHECKED_FROM_LOGIN', 'true'); } - // Only proceed if component is still mounted - if (!isMounted) return; - if (!status.auth_configured && status.access_token) { // If auth is not configured, use the guest token and redirect login(status.access_token, true, status.core_version, status.api_version) @@ -69,6 +59,12 @@ const LoginPage = () => { navigate('/') return } + + // Only set checkingAuth to false if we need to show the login page + if (isMounted) { + setCheckingAuth(false); + } + } catch (error) { console.error('Failed to check auth configuration:', error) // Also set checkingAuth to false in case of error @@ -85,6 +81,7 @@ const LoginPage = () => { // Cleanup function to prevent state updates after unmount return () => { isMounted = false; + setCheckingAuth(false); } }, [isAuthenticated, login, navigate])