import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { Toaster } from 'react-hot-toast'; import { useAuthStore } from '@/stores/authStore'; import { authApi } from '@/services/api'; import { useEffect } from 'react'; import Navbar from '@/components/Navbar'; import Sidebar from '@/components/Sidebar'; import Login from '@/pages/Login'; import Dashboard from '@/pages/Dashboard'; import Endpoints from '@/pages/Endpoints'; import ApiKeys from '@/pages/ApiKeys'; import Folders from '@/pages/Folders'; import Logs from '@/pages/Logs'; import Settings from '@/pages/Settings'; import SqlInterface from '@/pages/SqlInterface'; const queryClient = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: 1, }, }, }); function PrivateRoute({ children }: { children: React.ReactNode }) { const isAuthenticated = useAuthStore((state) => state.isAuthenticated); return isAuthenticated ? <>{children} : ; } function Layout({ children }: { children: React.ReactNode }) { return (
{children}
); } function App() { const { isAuthenticated, setUser } = useAuthStore(); // Load user data on app start if authenticated useEffect(() => { const loadUser = async () => { if (isAuthenticated) { try { const { data } = await authApi.getMe(); setUser(data); } catch (error) { console.error('Failed to load user:', error); } } }; loadUser(); }, [isAuthenticated, setUser]); return ( } /> } /> } /> } /> } /> } /> } /> } /> } /> ); } export default App;