Prevent login page show up when on auth is needed
This commit is contained in:
@@ -19,14 +19,13 @@ const AppContent = () => {
|
||||
|
||||
// Token validity check
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
|
||||
const checkAuth = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('LIGHTRAG-API-TOKEN')
|
||||
|
||||
if (token && isAuthenticated) {
|
||||
if (isMounted) setInitializing(false);
|
||||
setInitializing(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,21 +34,17 @@ const AppContent = () => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Auth initialization error:', error)
|
||||
if (isMounted && !isAuthenticated) {
|
||||
if (!isAuthenticated) {
|
||||
useAuthStore.getState().logout()
|
||||
}
|
||||
} finally {
|
||||
if (isMounted) {
|
||||
setInitializing(false)
|
||||
}
|
||||
setInitializing(false)
|
||||
}
|
||||
}
|
||||
|
||||
checkAuth()
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
setInitializing(false)
|
||||
}
|
||||
}, [isAuthenticated])
|
||||
|
||||
|
@@ -26,7 +26,6 @@ const LoginPage = () => {
|
||||
|
||||
// Check if authentication is configured, skip login if not
|
||||
useEffect(() => {
|
||||
let isMounted = true; // Flag to prevent state updates after unmount
|
||||
|
||||
const checkAuthConfig = async () => {
|
||||
// Prevent duplicate calls in Vite dev mode
|
||||
@@ -61,16 +60,12 @@ const LoginPage = () => {
|
||||
}
|
||||
|
||||
// Only set checkingAuth to false if we need to show the login page
|
||||
if (isMounted) {
|
||||
setCheckingAuth(false);
|
||||
}
|
||||
setCheckingAuth(false);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to check auth configuration:', error)
|
||||
// Also set checkingAuth to false in case of error
|
||||
if (isMounted) {
|
||||
setCheckingAuth(false);
|
||||
}
|
||||
setCheckingAuth(false);
|
||||
}
|
||||
// Removed finally block as we're setting checkingAuth earlier
|
||||
}
|
||||
@@ -80,8 +75,6 @@ const LoginPage = () => {
|
||||
|
||||
// Cleanup function to prevent state updates after unmount
|
||||
return () => {
|
||||
isMounted = false;
|
||||
setCheckingAuth(false);
|
||||
}
|
||||
}, [isAuthenticated, login, navigate])
|
||||
|
||||
|
Reference in New Issue
Block a user