// 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, Outlet } from 'react-router-dom'; import { useAuth } from '../context/AuthContext'; import { LoginPage } from '../../pages/LoginPage'; // ─── Lazy page imports ──────────────────────────────────────────────────────── // Each route bundle is loaded only when the route is first visited. LoginPage // is imported eagerly above since it's the first route rendered for a // logged-out visitor (see docs/figma-make-compatibility.md #4). 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 ShowcasePage = React.lazy(() => import('../../pages/ShowcasePage').then(m => ({ default: m.ShowcasePage })) ); 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 ───────────────────────────────────────────────────────────── // Layout routes + , not children-wrapping components — a guard that // conditionally renders a `children` prop breaks under Figma Make's inspector // wrapping (see docs/figma-make-compatibility.md #2). /** Redirects unauthenticated visitors to /login. */ function AuthedLayout() { const { user } = useAuth(); if (!user) return ; return ; } /** Redirects authenticated users away from auth-only pages. */ function GuestLayout() { const { user } = useAuth(); if (user) return ; return ; } // ─── 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 */} } /> } />
); }