From d3b2cff182705b7e5e586d84174a7efc522bb2de Mon Sep 17 00:00:00 2001 From: yangdx Date: Sun, 23 Mar 2025 02:00:59 +0800 Subject: [PATCH] Prevent login page show up when on auth is needed --- lightrag_webui/src/AppRouter.tsx | 11 +++-------- lightrag_webui/src/features/LoginPage.tsx | 11 ++--------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/lightrag_webui/src/AppRouter.tsx b/lightrag_webui/src/AppRouter.tsx index f0a07ad3..9aec0a14 100644 --- a/lightrag_webui/src/AppRouter.tsx +++ b/lightrag_webui/src/AppRouter.tsx @@ -19,14 +19,13 @@ const AppContent = () => { // Token validity check useEffect(() => { - let isMounted = true; const checkAuth = async () => { try { const token = localStorage.getItem('LIGHTRAG-API-TOKEN') if (token && isAuthenticated) { - if (isMounted) setInitializing(false); + setInitializing(false); return; } @@ -35,21 +34,17 @@ const AppContent = () => { } } catch (error) { console.error('Auth initialization error:', error) - if (isMounted && !isAuthenticated) { + if (!isAuthenticated) { useAuthStore.getState().logout() } } finally { - if (isMounted) { - setInitializing(false) - } + setInitializing(false) } } checkAuth() return () => { - isMounted = false; - setInitializing(false) } }, [isAuthenticated]) diff --git a/lightrag_webui/src/features/LoginPage.tsx b/lightrag_webui/src/features/LoginPage.tsx index 29217594..847a4c9e 100644 --- a/lightrag_webui/src/features/LoginPage.tsx +++ b/lightrag_webui/src/features/LoginPage.tsx @@ -26,7 +26,6 @@ const LoginPage = () => { // Check if authentication is configured, skip login if not useEffect(() => { - let isMounted = true; // Flag to prevent state updates after unmount const checkAuthConfig = async () => { // Prevent duplicate calls in Vite dev mode @@ -61,16 +60,12 @@ const LoginPage = () => { } // Only set checkingAuth to false if we need to show the login page - if (isMounted) { - setCheckingAuth(false); - } + setCheckingAuth(false); } catch (error) { console.error('Failed to check auth configuration:', error) // Also set checkingAuth to false in case of error - if (isMounted) { - setCheckingAuth(false); - } + setCheckingAuth(false); } // Removed finally block as we're setting checkingAuth earlier } @@ -80,8 +75,6 @@ const LoginPage = () => { // Cleanup function to prevent state updates after unmount return () => { - isMounted = false; - setCheckingAuth(false); } }, [isAuthenticated, login, navigate])