Prevent login page show up when on auth is needed

This commit is contained in:
yangdx
2025-03-23 01:16:53 +08:00
parent 9f81d34ce3
commit b72aa3e8ca
2 changed files with 9 additions and 11 deletions

View File

@@ -49,6 +49,7 @@ const AppContent = () => {
return () => { return () => {
isMounted = false; isMounted = false;
setInitializing(false)
} }
}, [isAuthenticated]) }, [isAuthenticated])

View File

@@ -31,7 +31,6 @@ const LoginPage = () => {
const checkAuthConfig = async () => { const checkAuthConfig = async () => {
// Prevent duplicate calls in Vite dev mode // Prevent duplicate calls in Vite dev mode
if (authCheckRef.current) { if (authCheckRef.current) {
if (isMounted) setCheckingAuth(false);
return; return;
} }
authCheckRef.current = true; authCheckRef.current = true;
@@ -46,20 +45,11 @@ const LoginPage = () => {
// Check auth status // Check auth status
const status = await getAuthStatus() 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 // 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'); 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 (!status.auth_configured && status.access_token) {
// If auth is not configured, use the guest token and redirect // If auth is not configured, use the guest token and redirect
login(status.access_token, true, status.core_version, status.api_version) login(status.access_token, true, status.core_version, status.api_version)
@@ -69,6 +59,12 @@ const LoginPage = () => {
navigate('/') navigate('/')
return return
} }
// Only set checkingAuth to false if we need to show the login page
if (isMounted) {
setCheckingAuth(false);
}
} catch (error) { } catch (error) {
console.error('Failed to check auth configuration:', error) console.error('Failed to check auth configuration:', error)
// Also set checkingAuth to false in case of error // Also set checkingAuth to false in case of error
@@ -85,6 +81,7 @@ const LoginPage = () => {
// Cleanup function to prevent state updates after unmount // Cleanup function to prevent state updates after unmount
return () => { return () => {
isMounted = false; isMounted = false;
setCheckingAuth(false);
} }
}, [isAuthenticated, login, navigate]) }, [isAuthenticated, login, navigate])