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