import { BrowserRouter, Routes, Route, Navigate, Outlet } from 'react-router-dom'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { AuthProvider, useAuth } from './contexts/AuthContext'; import { Layout } from './components/Layout'; import { Dashboard } from './pages/Dashboard'; import { Products } from './pages/Products'; import { Orders } from './pages/Orders'; import { Customers } from './pages/Customers'; import { Fiado } from './pages/Fiado'; import { Inventory } from './pages/Inventory'; import { Settings } from './pages/Settings'; import { Referrals } from './pages/Referrals'; import { Invoices } from './pages/Invoices'; import { Marketplace } from './pages/Marketplace'; import { Tokens } from './pages/Tokens'; import { CodiSpei } from './pages/CodiSpei'; import Login from './pages/Login'; import Register from './pages/Register'; const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: 1000 * 60 * 5, // 5 minutes retry: 1, }, }, }); // Protected route wrapper function ProtectedRoute() { const { isAuthenticated, isLoading } = useAuth(); if (isLoading) { return (
); } return isAuthenticated ? : ; } // Public route wrapper (redirect if authenticated) function PublicRoute() { const { isAuthenticated, isLoading } = useAuth(); if (isLoading) { return (
); } return isAuthenticated ? : ; } function App() { return ( {/* Public routes */} }> } /> } /> {/* Protected routes */} }> }> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Catch all */} } /> ); } export default App;