Fix guest login expiration problem
This commit is contained in:
@@ -22,6 +22,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 +56,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 +89,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 +121,16 @@ function App() {
|
|||||||
return (
|
return (
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
<TabVisibilityProvider>
|
<TabVisibilityProvider>
|
||||||
|
{initializing ? (
|
||||||
|
// Loading state while initializing
|
||||||
|
<div className="flex h-screen w-screen 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>
|
||||||
|
) : (
|
||||||
|
// 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 +156,7 @@ function App() {
|
|||||||
{enableHealthCheck && <StatusIndicator />}
|
{enableHealthCheck && <StatusIndicator />}
|
||||||
<ApiKeyAlert open={apiKeyAlertOpen} onOpenChange={handleApiKeyAlertOpenChange} />
|
<ApiKeyAlert open={apiKeyAlertOpen} onOpenChange={handleApiKeyAlertOpenChange} />
|
||||||
</main>
|
</main>
|
||||||
|
)}
|
||||||
</TabVisibilityProvider>
|
</TabVisibilityProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user