From e64131079e7384e60f6f2fa5df40062bee2f25e5 Mon Sep 17 00:00:00 2001 From: Fimeg Date: Fri, 31 Oct 2025 08:39:16 -0400 Subject: [PATCH] add automatic redirect from setup to login after completion - Add SetupCompletionChecker component that monitors health status - Automatically redirect to /login when server becomes healthy after setup - Improves user experience by eliminating manual navigation step --- aggregator-web/src/App.tsx | 10 +++- .../src/components/SetupCompletionChecker.tsx | 48 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 aggregator-web/src/components/SetupCompletionChecker.tsx diff --git a/aggregator-web/src/App.tsx b/aggregator-web/src/App.tsx index 48e3f97..82724e5 100644 --- a/aggregator-web/src/App.tsx +++ b/aggregator-web/src/App.tsx @@ -16,6 +16,7 @@ import AgentManagement from '@/pages/settings/AgentManagement'; import Login from '@/pages/Login'; import Setup from '@/pages/Setup'; import { WelcomeChecker } from '@/components/WelcomeChecker'; +import { SetupCompletionChecker } from '@/components/SetupCompletionChecker'; // Protected route component const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => { @@ -81,7 +82,14 @@ const App: React.FC = () => { {/* App routes */} {/* Setup route - shown when server needs configuration */} - } /> + + + + } + /> {/* Login route */} = ({ children }) => { + const [isSetupMode, setIsSetupMode] = useState(null); + const navigate = useNavigate(); + const location = useLocation(); + + useEffect(() => { + const checkSetupStatus = async () => { + try { + const data = await setupApi.checkHealth(); + + if (data.status === 'waiting for configuration') { + setIsSetupMode(true); + } else { + setIsSetupMode(false); + } + } catch (error) { + // If we can't reach the health endpoint, assume normal mode + setIsSetupMode(false); + } + }; + + checkSetupStatus(); + + // Check periodically for configuration changes + const interval = setInterval(checkSetupStatus, 3000); + + return () => clearInterval(interval); + }, []); + + // If we're on the setup page and server is now healthy, redirect to login + useEffect(() => { + if (isSetupMode === false && location.pathname === '/setup') { + console.log('Setup completed - redirecting to login'); + navigate('/login', { replace: true }); + } + }, [isSetupMode, location.pathname, navigate]); + + // Always render children - this component only handles redirects + return <>{children}; +}; \ No newline at end of file