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