Merge pull request #1270 from danielaskdd/main

Fix guest login expiration problem
This commit is contained in:
Daniel.y
2025-04-05 06:21:20 +08:00
committed by GitHub
5 changed files with 193 additions and 125 deletions

View File

@@ -1 +1 @@
__api_version__ = "0132" __api_version__ = "0133"

File diff suppressed because one or more lines are too long

View File

@@ -8,7 +8,7 @@
<link rel="icon" type="image/svg+xml" href="logo.png" /> <link rel="icon" type="image/svg+xml" href="logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lightrag</title> <title>Lightrag</title>
<script type="module" crossorigin src="/webui/assets/index-D8Hd4VcS.js"></script> <script type="module" crossorigin src="/webui/assets/index-Cb_7ABt2.js"></script>
<link rel="stylesheet" crossorigin href="/webui/assets/index-f0HMqdqP.css"> <link rel="stylesheet" crossorigin href="/webui/assets/index-f0HMqdqP.css">
</head> </head>
<body> <body>

View File

@@ -3,12 +3,13 @@ import ThemeProvider from '@/components/ThemeProvider'
import TabVisibilityProvider from '@/contexts/TabVisibilityProvider' import TabVisibilityProvider from '@/contexts/TabVisibilityProvider'
import ApiKeyAlert from '@/components/ApiKeyAlert' import ApiKeyAlert from '@/components/ApiKeyAlert'
import StatusIndicator from '@/components/status/StatusIndicator' import StatusIndicator from '@/components/status/StatusIndicator'
import { healthCheckInterval } from '@/lib/constants' import { healthCheckInterval, SiteInfo, webuiPrefix } from '@/lib/constants'
import { useBackendState, useAuthStore } from '@/stores/state' import { useBackendState, useAuthStore } from '@/stores/state'
import { useSettingsStore } from '@/stores/settings' import { useSettingsStore } from '@/stores/settings'
import { getAuthStatus } from '@/api/lightrag' import { getAuthStatus } from '@/api/lightrag'
import SiteHeader from '@/features/SiteHeader' import SiteHeader from '@/features/SiteHeader'
import { InvalidApiKeyError, RequireApiKeError } from '@/api/lightrag' import { InvalidApiKeyError, RequireApiKeError } from '@/api/lightrag'
import { ZapIcon } from 'lucide-react'
import GraphViewer from '@/features/GraphViewer' import GraphViewer from '@/features/GraphViewer'
import DocumentManager from '@/features/DocumentManager' import DocumentManager from '@/features/DocumentManager'
@@ -22,6 +23,7 @@ function App() {
const enableHealthCheck = useSettingsStore.use.enableHealthCheck() const enableHealthCheck = useSettingsStore.use.enableHealthCheck()
const currentTab = useSettingsStore.use.currentTab() const currentTab = useSettingsStore.use.currentTab()
const [apiKeyAlertOpen, setApiKeyAlertOpen] = useState(false) 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 versionCheckRef = useRef(false); // Prevent duplicate calls in Vite dev mode
const handleApiKeyAlertOpenChange = useCallback((open: boolean) => { const handleApiKeyAlertOpenChange = useCallback((open: boolean) => {
@@ -55,17 +57,31 @@ function App() {
// Check if version info was already obtained in login page // Check if version info was already obtained in login page
const versionCheckedFromLogin = sessionStorage.getItem('VERSION_CHECKED_FROM_LOGIN') === 'true'; const versionCheckedFromLogin = sessionStorage.getItem('VERSION_CHECKED_FROM_LOGIN') === 'true';
if (versionCheckedFromLogin) return; if (versionCheckedFromLogin) {
setInitializing(false); // Skip initialization if already checked
return;
}
try {
setInitializing(true); // Start initialization
// Get version info // Get version info
const token = localStorage.getItem('LIGHTRAG-API-TOKEN'); const token = localStorage.getItem('LIGHTRAG-API-TOKEN');
if (!token) return;
try {
const status = await getAuthStatus(); 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; const isGuestMode = status.auth_mode === 'disabled' || useAuthStore.getState().isGuestMode;
// Update version info and webui title while maintaining login state
useAuthStore.getState().login( useAuthStore.getState().login(
token, token,
isGuestMode, isGuestMode,
@@ -74,12 +90,15 @@ function App() {
status.webui_title || null, status.webui_title || null,
status.webui_description || null status.webui_description || null
); );
}
// Set flag to indicate version info has been checked // Set flag to indicate version info has been checked
sessionStorage.setItem('VERSION_CHECKED_FROM_LOGIN', 'true'); sessionStorage.setItem('VERSION_CHECKED_FROM_LOGIN', 'true');
}
} catch (error) { } catch (error) {
console.error('Failed to get version info:', 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,6 +122,37 @@ function App() {
return ( return (
<ThemeProvider> <ThemeProvider>
<TabVisibilityProvider> <TabVisibilityProvider>
{initializing ? (
// Loading state while initializing with simplified header
<div className="flex h-screen w-screen flex-col">
{/* Simplified header during initialization - matches SiteHeader structure */}
<header className="border-border/40 bg-background/95 supports-[backdrop-filter]:bg-background/60 sticky top-0 z-50 flex h-10 w-full border-b px-4 backdrop-blur">
<div className="min-w-[200px] w-auto flex items-center">
<a href={webuiPrefix} className="flex items-center gap-2">
<ZapIcon className="size-4 text-emerald-400" aria-hidden="true" />
<span className="font-bold md:inline-block">{SiteInfo.name}</span>
</a>
</div>
{/* Empty middle section to maintain layout */}
<div className="flex h-10 flex-1 items-center justify-center">
</div>
{/* Empty right section to maintain layout */}
<nav className="w-[200px] flex items-center justify-end">
</nav>
</header>
{/* Loading indicator in content area */}
<div className="flex flex-1 items-center justify-center">
<div className="text-center">
<div className="mb-2 h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"></div>
<p>Initializing...</p>
</div>
</div>
</div>
) : (
// Main content after initialization
<main className="flex h-screen w-screen overflow-hidden"> <main className="flex h-screen w-screen overflow-hidden">
<Tabs <Tabs
defaultValue={currentTab} defaultValue={currentTab}
@@ -128,6 +178,7 @@ function App() {
{enableHealthCheck && <StatusIndicator />} {enableHealthCheck && <StatusIndicator />}
<ApiKeyAlert open={apiKeyAlertOpen} onOpenChange={handleApiKeyAlertOpenChange} /> <ApiKeyAlert open={apiKeyAlertOpen} onOpenChange={handleApiKeyAlertOpenChange} />
</main> </main>
)}
</TabVisibilityProvider> </TabVisibilityProvider>
</ThemeProvider> </ThemeProvider>
) )

View File

@@ -1,4 +1,4 @@
import { useCallback } from 'react' import { useCallback, useEffect } from 'react'
import { AsyncSelect } from '@/components/ui/AsyncSelect' import { AsyncSelect } from '@/components/ui/AsyncSelect'
import { useSettingsStore } from '@/stores/settings' import { useSettingsStore } from '@/stores/settings'
import { useGraphStore } from '@/stores/graph' import { useGraphStore } from '@/stores/graph'
@@ -56,6 +56,23 @@ const GraphLabels = () => {
[getSearchEngine] [getSearchEngine]
) )
// Validate if current queryLabel exists in allDatabaseLabels
useEffect(() => {
// Only update label when all conditions are met:
// 1. allDatabaseLabels is loaded (length > 1, as it has at least '*' by default)
// 2. Current label is not the default '*'
// 3. Current label doesn't exist in allDatabaseLabels
if (
allDatabaseLabels.length > 1 &&
label &&
label !== '*' &&
!allDatabaseLabels.includes(label)
) {
console.log(`Label "${label}" not found in available labels, resetting to default`);
useSettingsStore.getState().setQueryLabel('*');
}
}, [allDatabaseLabels, label]);
const handleRefresh = useCallback(() => { const handleRefresh = useCallback(() => {
// Reset fetch status flags // Reset fetch status flags
useGraphStore.getState().setLabelsFetchAttempted(false) useGraphStore.getState().setLabelsFetchAttempted(false)