import { useEffect } from "react"; import { Switch, Route, Router, useLocation } from "wouter"; import { useHashLocation } from "wouter/use-hash-location"; import { queryClient } from "./lib/queryClient"; import { QueryClientProvider } from "@tanstack/react-query"; import { Toaster } from "@/components/ui/toaster"; import { TooltipProvider } from "@/components/ui/tooltip"; import { SidebarProvider } from "@/components/ui/sidebar"; import { AppSidebar } from "@/components/app-sidebar"; import { TopBar } from "@/components/top-bar"; import { SymbolProvider } from "@/lib/symbol-context"; import { ThemeProvider } from "@/lib/theme-context"; import { AuthProvider, useAuth } from "@/lib/auth-context"; import DashboardPage from "@/pages/dashboard"; import GammaLevelsPage from "@/pages/gamma-levels"; import ExpiryMatrixPage from "@/pages/expiry-matrix"; import ScreenerPage from "@/pages/screener"; import SettingsPage from "@/pages/settings"; import AccountPage from "@/pages/account"; import LoginPage from "@/pages/login"; import NotFound from "@/pages/not-found"; import { Loader2 } from "lucide-react"; function usePageTitle(): string { const [location] = useLocation(); if (location.startsWith("/gamma")) return "Gamma Levels"; if (location.startsWith("/expiry")) return "Expiry Matrix"; if (location.startsWith("/screener")) return "Screener"; if (location.startsWith("/settings")) return "Settings & API"; if (location.startsWith("/account")) return "Account"; if (location.startsWith("/login")) return "Sign In"; return "Dashboard"; } // Redirect to login if not authenticated function ProtectedRoute({ component: Component }: { component: () => JSX.Element }) { const { user, loading } = useAuth(); const [, setLocation] = useLocation(); // Must call hooks unconditionally before any early return useEffect(() => { if (!loading && !user) { setLocation("/login"); } }, [loading, user, setLocation]); if (loading) { return (