diff --git a/src/App.jsx b/src/App.jsx new file mode 100644 index 0000000..b051536 --- /dev/null +++ b/src/App.jsx @@ -0,0 +1,80 @@ +import { Toaster } from "@/components/ui/toaster" +import { QueryClientProvider } from '@tanstack/react-query' +import { queryClientInstance } from '@/lib/query-client' +import { pagesConfig } from './pages.config' +import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; +import PageNotFound from './lib/PageNotFound'; +import { AuthProvider, useAuth } from '@/lib/AuthContext'; +import UserNotRegisteredError from '@/components/UserNotRegisteredError'; + +const { Pages, Layout, mainPage } = pagesConfig; +const mainPageKey = mainPage ?? Object.keys(Pages)[0]; +const MainPage = mainPageKey ? Pages[mainPageKey] : <>; + +const LayoutWrapper = ({ children, currentPageName }) => Layout ? + {children} + : <>{children}; + +const AuthenticatedApp = () => { + const { isLoadingAuth, isLoadingPublicSettings, authError, navigateToLogin } = useAuth(); + + // Show loading spinner while checking app public settings or auth + if (isLoadingPublicSettings || isLoadingAuth) { + return ( +
+
+
+ ); + } + + // Handle authentication errors + if (authError) { + if (authError.type === 'user_not_registered') { + return ; + } else if (authError.type === 'auth_required') { + // Redirect to login automatically + navigateToLogin(); + return null; + } + } + + // Render the main app + return ( + + + + + } /> + {Object.entries(Pages).map(([path, Page]) => ( + + + + } + /> + ))} + } /> + + ); +}; + + +function App() { + + return ( + + + + + + + + + ) +} + +export default App