import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'
import { AuthProvider, useAuth } from '@/context/AuthContext'
import { usePageTracking } from '@/hooks/useAnalytics'
import { initAnalytics } from '@/lib/analytics'
import { Home } from '@/pages/Home'
import { Login } from '@/pages/Login'
import { Register } from '@/pages/Register'
import { Dashboard } from '@/pages/Dashboard'
import { Setup } from '@/pages/Setup'
import { Settings } from '@/pages/Settings'
import { ForgotPassword } from '@/pages/ForgotPassword'
import { ResetPassword } from '@/pages/ResetPassword'
import { VerifyEmail } from '@/pages/VerifyEmail'
import { Privacy } from '@/pages/Privacy'
import { Imprint } from '@/pages/Imprint'
// Initialize analytics on app startup
initAnalytics()
// Loading spinner component
function LoadingSpinner() {
return (
)
}
// Protected route wrapper - requires authentication
function ProtectedRoute({ children }: { children: React.ReactNode }) {
const { user, loading } = useAuth()
if (loading) {
return
}
if (!user) {
return
}
return <>{children}>
}
// Public route that redirects to dashboard if logged in
function PublicRoute({ children }: { children: React.ReactNode }) {
const { user, loading } = useAuth()
if (loading) {
return
}
if (user) {
return
}
return <>{children}>
}
function AppRoutes() {
// Track page views on route changes
usePageTracking()
return (
{/* Public pages */}
} />
{/* Auth pages - redirect to dashboard if logged in */}
}
/>
}
/>
{/* Password recovery - always accessible */}
} />
} />
{/* Email verification - always accessible */}
} />
{/* Legal pages - always accessible */}
} />
} />
{/* Protected pages - require authentication */}
}
/>
}
/>
}
/>
{/* Catch all - redirect to home */}
} />
)
}
function App() {
return (
)
}
export default App