yangdx
commited on
Commit
·
6fd7cb8
1
Parent(s):
d27ca31
Prevent login page show up when on auth is needed
Browse files
lightrag_webui/src/AppRouter.tsx
CHANGED
@@ -19,14 +19,13 @@ const AppContent = () => {
|
|
19 |
|
20 |
// Token validity check
|
21 |
useEffect(() => {
|
22 |
-
let isMounted = true;
|
23 |
|
24 |
const checkAuth = async () => {
|
25 |
try {
|
26 |
const token = localStorage.getItem('LIGHTRAG-API-TOKEN')
|
27 |
|
28 |
if (token && isAuthenticated) {
|
29 |
-
|
30 |
return;
|
31 |
}
|
32 |
|
@@ -35,21 +34,17 @@ const AppContent = () => {
|
|
35 |
}
|
36 |
} catch (error) {
|
37 |
console.error('Auth initialization error:', error)
|
38 |
-
if (
|
39 |
useAuthStore.getState().logout()
|
40 |
}
|
41 |
} finally {
|
42 |
-
|
43 |
-
setInitializing(false)
|
44 |
-
}
|
45 |
}
|
46 |
}
|
47 |
|
48 |
checkAuth()
|
49 |
|
50 |
return () => {
|
51 |
-
isMounted = false;
|
52 |
-
setInitializing(false)
|
53 |
}
|
54 |
}, [isAuthenticated])
|
55 |
|
|
|
19 |
|
20 |
// Token validity check
|
21 |
useEffect(() => {
|
|
|
22 |
|
23 |
const checkAuth = async () => {
|
24 |
try {
|
25 |
const token = localStorage.getItem('LIGHTRAG-API-TOKEN')
|
26 |
|
27 |
if (token && isAuthenticated) {
|
28 |
+
setInitializing(false);
|
29 |
return;
|
30 |
}
|
31 |
|
|
|
34 |
}
|
35 |
} catch (error) {
|
36 |
console.error('Auth initialization error:', error)
|
37 |
+
if (!isAuthenticated) {
|
38 |
useAuthStore.getState().logout()
|
39 |
}
|
40 |
} finally {
|
41 |
+
setInitializing(false)
|
|
|
|
|
42 |
}
|
43 |
}
|
44 |
|
45 |
checkAuth()
|
46 |
|
47 |
return () => {
|
|
|
|
|
48 |
}
|
49 |
}, [isAuthenticated])
|
50 |
|
lightrag_webui/src/features/LoginPage.tsx
CHANGED
@@ -26,7 +26,6 @@ const LoginPage = () => {
|
|
26 |
|
27 |
// Check if authentication is configured, skip login if not
|
28 |
useEffect(() => {
|
29 |
-
let isMounted = true; // Flag to prevent state updates after unmount
|
30 |
|
31 |
const checkAuthConfig = async () => {
|
32 |
// Prevent duplicate calls in Vite dev mode
|
@@ -61,16 +60,12 @@ const LoginPage = () => {
|
|
61 |
}
|
62 |
|
63 |
// Only set checkingAuth to false if we need to show the login page
|
64 |
-
|
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
|
71 |
-
|
72 |
-
setCheckingAuth(false);
|
73 |
-
}
|
74 |
}
|
75 |
// Removed finally block as we're setting checkingAuth earlier
|
76 |
}
|
@@ -80,8 +75,6 @@ const LoginPage = () => {
|
|
80 |
|
81 |
// Cleanup function to prevent state updates after unmount
|
82 |
return () => {
|
83 |
-
isMounted = false;
|
84 |
-
setCheckingAuth(false);
|
85 |
}
|
86 |
}, [isAuthenticated, login, navigate])
|
87 |
|
|
|
26 |
|
27 |
// Check if authentication is configured, skip login if not
|
28 |
useEffect(() => {
|
|
|
29 |
|
30 |
const checkAuthConfig = async () => {
|
31 |
// Prevent duplicate calls in Vite dev mode
|
|
|
60 |
}
|
61 |
|
62 |
// Only set checkingAuth to false if we need to show the login page
|
63 |
+
setCheckingAuth(false);
|
|
|
|
|
64 |
|
65 |
} catch (error) {
|
66 |
console.error('Failed to check auth configuration:', error)
|
67 |
// Also set checkingAuth to false in case of error
|
68 |
+
setCheckingAuth(false);
|
|
|
|
|
69 |
}
|
70 |
// Removed finally block as we're setting checkingAuth earlier
|
71 |
}
|
|
|
75 |
|
76 |
// Cleanup function to prevent state updates after unmount
|
77 |
return () => {
|
|
|
|
|
78 |
}
|
79 |
}, [isAuthenticated, login, navigate])
|
80 |
|