diff --git a/lightrag_webui/src/App.tsx b/lightrag_webui/src/App.tsx index eba7cfc8..a978c3da 100644 --- a/lightrag_webui/src/App.tsx +++ b/lightrag_webui/src/App.tsx @@ -22,6 +22,7 @@ function App() { const enableHealthCheck = useSettingsStore.use.enableHealthCheck() const currentTab = useSettingsStore.use.currentTab() const [apiKeyAlertOpen, setApiKeyAlertOpen] = useState(false) + const [initializing, setInitializing] = useState(true) // Add initializing state const versionCheckRef = useRef(false); // Prevent duplicate calls in Vite dev mode const handleApiKeyAlertOpenChange = useCallback((open: boolean) => { @@ -55,17 +56,31 @@ function App() { // Check if version info was already obtained in login page const versionCheckedFromLogin = sessionStorage.getItem('VERSION_CHECKED_FROM_LOGIN') === 'true'; - if (versionCheckedFromLogin) return; - - // Get version info - const token = localStorage.getItem('LIGHTRAG-API-TOKEN'); - if (!token) return; + if (versionCheckedFromLogin) { + setInitializing(false); // Skip initialization if already checked + return; + } try { + setInitializing(true); // Start initialization + + // Get version info + const token = localStorage.getItem('LIGHTRAG-API-TOKEN'); const status = await getAuthStatus(); - if (status.core_version || status.api_version || status.webui_title || status.webui_description) { + + // If auth is not configured and a new token is returned, use the new token + if (!status.auth_configured && status.access_token) { + useAuthStore.getState().login( + status.access_token, // Use the new token + true, // Guest mode + status.core_version, + status.api_version, + status.webui_title || null, + status.webui_description || null + ); + } else if (token && (status.core_version || status.api_version || status.webui_title || status.webui_description)) { + // Otherwise use the old token (if it exists) const isGuestMode = status.auth_mode === 'disabled' || useAuthStore.getState().isGuestMode; - // Update version info and webui title while maintaining login state useAuthStore.getState().login( token, isGuestMode, @@ -74,12 +89,15 @@ function App() { status.webui_title || null, status.webui_description || null ); - - // Set flag to indicate version info has been checked - sessionStorage.setItem('VERSION_CHECKED_FROM_LOGIN', 'true'); } + + // Set flag to indicate version info has been checked + sessionStorage.setItem('VERSION_CHECKED_FROM_LOGIN', 'true'); } catch (error) { console.error('Failed to get version info:', error); + } finally { + // Ensure initializing is set to false even if there's an error + setInitializing(false); } }; @@ -103,31 +121,42 @@ function App() { return ( -
- - -
- - - - - - - - - - - - + {initializing ? ( + // Loading state while initializing +
+
+
+

Initializing...

- - {enableHealthCheck && } - -
+ + ) : ( + // Main content after initialization +
+ + +
+ + + + + + + + + + + + +
+
+ {enableHealthCheck && } + +
+ )}
)