56 lines
2.5 KiB
TypeScript
56 lines
2.5 KiB
TypeScript
import React from 'react';
|
|
import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
|
|
import { useAuth } from './context/AuthContext';
|
|
import { Toaster } from 'sonner';
|
|
import Auth from './pages/Auth';
|
|
import AdminTokenGate from './components/AdminTokenGate';
|
|
import Navbar from './components/Navbar';
|
|
import LandingPage from './pages/Landing';
|
|
import OnboardingPage from './pages/Onboarding';
|
|
import PassengerRidePage from './pages/PassengerRide';
|
|
import DriverWorkstationPage from './pages/DriverWorkstation';
|
|
import CirclesPage from './pages/Circles';
|
|
import HistoryPage from './pages/History';
|
|
import OnboardingPage from './pages/Onboarding';
|
|
import AdminPage from './pages/Admin';
|
|
|
|
function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
|
const { user, isLoading } = useAuth();
|
|
const location = useLocation();
|
|
if (isLoading) return <div className="p-8 text-center text-muted-foreground">Loading session...</div>;
|
|
if (!user) {
|
|
const returnTo = encodeURIComponent(location.pathname + location.search);
|
|
return <Navigate to={'/auth?returnTo=' + returnTo} replace />;
|
|
}
|
|
return <>{children}</>;
|
|
}
|
|
|
|
export default function App() {
|
|
const location = useLocation();
|
|
const isPublicShellRoute = location.pathname === '/' || location.pathname === '/auth' || location.pathname.startsWith('/admin');
|
|
|
|
return (
|
|
<>
|
|
<Toaster position="top-right" />
|
|
<div className="min-h-screen flex flex-col">
|
|
{!isPublicShellRoute && <Navbar />}
|
|
<main className="flex-1">
|
|
<Routes>
|
|
<Route path="/auth" element={<Auth />} />
|
|
<Route path="/" element={<LandingPage />} />
|
|
<Route path="/app" element={<ProtectedRoute><OnboardingPage /></ProtectedRoute>} />
|
|
<Route path="/app/ride" element={<ProtectedRoute><PassengerRidePage /></ProtectedRoute>} />
|
|
<Route path="/app/driver" element={<ProtectedRoute><DriverWorkstationPage /></ProtectedRoute>} />
|
|
<Route path="/app/circles" element={<ProtectedRoute><CirclesPage /></ProtectedRoute>} />
|
|
<Route path="/app/history" element={<ProtectedRoute><HistoryPage /></ProtectedRoute>} />
|
|
<Route path="/app/onboarding" element={<ProtectedRoute><OnboardingPage /></ProtectedRoute>} />
|
|
<Route path="/admin" element={<AdminTokenGate><AdminPage /></AdminTokenGate>} />
|
|
<Route path="*" element={<Navigate to="/" replace />} />
|
|
</Routes>
|
|
</main>
|
|
|
|
</div>
|
|
</>
|
|
);
|
|
}
|