From 531a7fdbcc89cf4d0ea057bcb5c56f8cd5681214 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Wed, 19 Nov 2025 12:35:29 +0000 Subject: [PATCH] again --- frontend/src/proprietary/routes/Landing.tsx | 55 ++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/frontend/src/proprietary/routes/Landing.tsx b/frontend/src/proprietary/routes/Landing.tsx index 53d5e2b6e3..3fd5e0796a 100644 --- a/frontend/src/proprietary/routes/Landing.tsx +++ b/frontend/src/proprietary/routes/Landing.tsx @@ -6,6 +6,7 @@ import HomePage from '@app/pages/HomePage' // Login component is used via routing, not directly imported import FirstLoginModal from '@app/components/shared/FirstLoginModal' import { accountService } from '@app/services/accountService' +import { BASE_PATH } from '@app/constants/app' /** * Landing component - Smart router based on authentication status @@ -16,11 +17,12 @@ import { accountService } from '@app/services/accountService' */ export default function Landing() { const { session, loading: authLoading, refreshSession } = useAuth(); - const { config, loading: configLoading } = useAppConfig(); + const { config, loading: configLoading, error: configError } = useAppConfig(); const location = useLocation(); const [isFirstLogin, setIsFirstLogin] = useState(false); const [checkingFirstLogin, setCheckingFirstLogin] = useState(false); const [username, setUsername] = useState(''); + const [backendCheckFailed, setBackendCheckFailed] = useState(false); const loading = authLoading || configLoading; @@ -54,13 +56,64 @@ export default function Landing() { // The auth system will automatically redirect to login when session is null } + // If AppConfig failed to load, check if backend is down + useEffect(() => { + let isMounted = true; + + // Only check if config has an error and we haven't already redirected + if (configError && !backendCheckFailed && !configLoading) { + console.debug('[Landing] Config error detected, checking backend status'); + + const checkBackend = async () => { + try { + const response = await fetch(`${BASE_PATH}/api/v1/info/status`, { + cache: 'no-cache' + }); + + if (!isMounted) return; + + // If backend responds, it's up - continue normally + if (response.ok) { + console.debug('[Landing] Backend is up despite config error'); + return; + } + + // Backend returned error - redirect to startup page + console.debug('[Landing] Backend not ready, redirecting to startup page'); + setBackendCheckFailed(true); + sessionStorage.setItem('backendStartupRedirect', location.pathname + location.search); + } catch (err) { + // Network error - backend is down + if (!isMounted) return; + + console.debug('[Landing] Backend unavailable (network error), redirecting to startup page'); + setBackendCheckFailed(true); + sessionStorage.setItem('backendStartupRedirect', location.pathname + location.search); + } + }; + + checkBackend(); + } + + return () => { + isMounted = false; + }; + }, [configError, configLoading, location, backendCheckFailed]); + console.log('[Landing] State:', { pathname: location.pathname, loading, hasSession: !!session, loginEnabled: config?.enableLogin, + configError, + backendCheckFailed, }); + // Redirect to backend startup if backend check failed + if (backendCheckFailed) { + return ; + } + // Show loading while checking auth and config if (loading || checkingFirstLogin) { return (