yangdx commited on
Commit
17643b8
·
1 Parent(s): 86d3b4b

Prevent login page show up when on auth is needed

Browse files
lightrag_webui/src/AppRouter.tsx CHANGED
@@ -49,6 +49,7 @@ const AppContent = () => {
49
 
50
  return () => {
51
  isMounted = false;
 
52
  }
53
  }, [isAuthenticated])
54
 
 
49
 
50
  return () => {
51
  isMounted = false;
52
+ setInitializing(false)
53
  }
54
  }, [isAuthenticated])
55
 
lightrag_webui/src/features/LoginPage.tsx CHANGED
@@ -31,7 +31,6 @@ const LoginPage = () => {
31
  const checkAuthConfig = async () => {
32
  // Prevent duplicate calls in Vite dev mode
33
  if (authCheckRef.current) {
34
- if (isMounted) setCheckingAuth(false);
35
  return;
36
  }
37
  authCheckRef.current = true;
@@ -46,20 +45,11 @@ const LoginPage = () => {
46
  // Check auth status
47
  const status = await getAuthStatus()
48
 
49
- // Set checkingAuth to false immediately after getAuthStatus
50
- // This allows the login page to render while other processing continues
51
- if (isMounted) {
52
- setCheckingAuth(false);
53
- }
54
-
55
  // Set session flag for version check to avoid duplicate checks in App component
56
- if (isMounted && (status.core_version || status.api_version)) {
57
  sessionStorage.setItem('VERSION_CHECKED_FROM_LOGIN', 'true');
58
  }
59
 
60
- // Only proceed if component is still mounted
61
- if (!isMounted) return;
62
-
63
  if (!status.auth_configured && status.access_token) {
64
  // If auth is not configured, use the guest token and redirect
65
  login(status.access_token, true, status.core_version, status.api_version)
@@ -69,6 +59,12 @@ const LoginPage = () => {
69
  navigate('/')
70
  return
71
  }
 
 
 
 
 
 
72
  } catch (error) {
73
  console.error('Failed to check auth configuration:', error)
74
  // Also set checkingAuth to false in case of error
@@ -85,6 +81,7 @@ const LoginPage = () => {
85
  // Cleanup function to prevent state updates after unmount
86
  return () => {
87
  isMounted = false;
 
88
  }
89
  }, [isAuthenticated, login, navigate])
90
 
 
31
  const checkAuthConfig = async () => {
32
  // Prevent duplicate calls in Vite dev mode
33
  if (authCheckRef.current) {
 
34
  return;
35
  }
36
  authCheckRef.current = true;
 
45
  // Check auth status
46
  const status = await getAuthStatus()
47
 
 
 
 
 
 
 
48
  // Set session flag for version check to avoid duplicate checks in App component
49
+ if (status.core_version || status.api_version) {
50
  sessionStorage.setItem('VERSION_CHECKED_FROM_LOGIN', 'true');
51
  }
52
 
 
 
 
53
  if (!status.auth_configured && status.access_token) {
54
  // If auth is not configured, use the guest token and redirect
55
  login(status.access_token, true, status.core_version, status.api_version)
 
59
  navigate('/')
60
  return
61
  }
62
+
63
+ // Only set checkingAuth to false if we need to show the login page
64
+ if (isMounted) {
65
+ setCheckingAuth(false);
66
+ }
67
+
68
  } catch (error) {
69
  console.error('Failed to check auth configuration:', error)
70
  // Also set checkingAuth to false in case of error
 
81
  // Cleanup function to prevent state updates after unmount
82
  return () => {
83
  isMounted = false;
84
+ setCheckingAuth(false);
85
  }
86
  }, [isAuthenticated, login, navigate])
87