import { useEffect, useState } from 'react'; import { Routes, Route, Navigate } from 'react-router-dom'; import { useAuthStore } from './store/authStore'; import { ThemeProvider } from './contexts/ThemeContext'; import AppLayout from './components/Layout/AppLayout'; import LoginForm from './components/Auth/LoginForm'; import RegisterForm from './components/Auth/RegisterForm'; import ForgotPassword from './components/Auth/ForgotPassword'; import ResetPassword from './components/Auth/ResetPassword'; import AuthCallback from './components/Auth/AuthCallback'; import Dashboard from './components/Dashboard/Dashboard'; import SettingsPage from './components/Settings/SettingsPage'; import ProjectEditor from './components/ProjectEditor/ProjectEditor'; import ErrorBoundary from './components/ErrorBoundary'; import WebSocketProvider from './components/WebSocketProvider'; function ProtectedRoute({ children }: { children: React.ReactNode }) { const { token, initialized } = useAuthStore(); if (!initialized) { return (
); } if (!token) return ; return <>{children}; } function PublicRoute({ children }: { children: React.ReactNode }) { const { token, initialized } = useAuthStore(); if (!initialized) { return (
); } if (token) return ; return <>{children}; } export default function App() { const init = useAuthStore((s) => s.init); const [ready, setReady] = useState(false); useEffect(() => { init().finally(() => setReady(true)); }, [init]); if (!ready) return null; return (
} /> } /> } /> } /> } /> } /> } /> } /> } /> } />
); }