// Local dev-reference copy — real scaffolds get this file's content from // `generateAuthGuard()` in bin/cli.ts, not from this file on disk. import React from 'react'; import { Routes, Route, Navigate } from 'react-router-dom'; import { useAuth } from '../context/AuthContext'; // ─── Lazy page imports ──────────────────────────────────────────────────────── // Each route bundle is loaded only when the route is first visited. const LoginPage = React.lazy(() => import('../../pages/LoginPage').then(m => ({ default: m.LoginPage })) ); const ForgotPasswordPage = React.lazy(() => import('../../pages/ForgotPasswordPage').then(m => ({ default: m.ForgotPasswordPage })) ); const VerifyEmailPage = React.lazy(() => import('../../pages/VerifyEmailPage').then(m => ({ default: m.VerifyEmailPage })) ); const ResetPasswordPage = React.lazy(() => import('../../pages/ResetPasswordPage').then(m => ({ default: m.ResetPasswordPage })) ); const HomePage = React.lazy(() => import('../../pages/HomePage').then(m => ({ default: m.HomePage })) ); const TemplatePage = React.lazy(() => import('../../pages/TemplatePage').then(m => ({ default: m.TemplatePage })) ); const AssistantPage = React.lazy(() => import('../../pages/AssistantPage').then(m => ({ default: m.AssistantPage })) ); // FDM integration spike — not part of the CLI scaffold, see FdmAssistantPage.tsx. const FdmAssistantPage = React.lazy(() => import('../../pages/FdmAssistantPage').then(m => ({ default: m.FdmAssistantPage })) ); const SettingsPage = React.lazy(() => import('../../pages/SettingsPage').then(m => ({ default: m.SettingsPage })) ); const LandingPage = React.lazy(() => import('../../pages/LandingPage').then(m => ({ default: m.LandingPage })) ); // ─── Route guards ───────────────────────────────────────────────────────────── /** Redirects unauthenticated visitors to /login. */ function ProtectedRoute({ children }: { children: React.ReactNode }) { const { user, isLoading } = useAuth(); if (isLoading) return null; if (!user) return ; return <>{children}; } /** Redirects authenticated users away from auth-only pages. */ function GuestRoute({ children }: { children: React.ReactNode }) { const { user, isLoading } = useAuth(); if (isLoading) return null; if (user) return ; return <>{children}; } // ─── Bridge for LoginPage ───────────────────────────────────────────────────── // LoginPage expects an onLogin prop — this bridge wires AuthContext.login to it, // keeping the LoginPage component decoupled from the AuthContext. function LoginPageWithAuth() { const { login } = useAuth(); return ; } // ─── Route tree ─────────────────────────────────────────────────────────────── export function AuthGuard() { const { user } = useAuth(); return (
{/* Public pages — accessible to everyone, no auth redirect */} } /> {/* Auth pages — redirect to /home when already signed in */} } /> } /> } /> } /> {/* Protected pages */} } /> } /> } /> } /> } /> {/* Fallback */} } /> } />
); }