import { BrowserRouter, Routes, Route, Navigate, useLocation } from "react-router-dom"; import { Toaster } from "sonner"; import { AuthProvider, useAuth } from "./lib/auth"; import { ProfileProvider, useProfile } from "./lib/profile"; import ProtectedRoute from "./components/ProtectedRoute"; import Navbar from "./components/Navbar"; import GrainOverlay from "./components/GrainOverlay"; import Login from "./pages/Login"; import Register from "./pages/Register"; import Browse from "./pages/Browse"; import MyList from "./pages/MyList"; import Search from "./pages/Search"; import Player from "./pages/Player"; import Requests from "./pages/Requests"; import Admin from "./pages/Admin"; import AdminUpload from "./pages/AdminUpload"; import Settings from "./pages/Settings"; import RadarrImport from "./pages/RadarrImport"; import ProfileSelect from "./pages/ProfileSelect"; import TranscodeQueue from "./pages/TranscodeQueue"; const ProfileGate = ({ children }) => { const { user, loading: authLoading } = useAuth(); const { active, loading: profLoading } = useProfile(); const loc = useLocation(); if (authLoading || profLoading) { return
Loading…
; } if (!user) return ; if (!active) return ; return children; }; const AdminGate = ({ children }) => { const { user, loading } = useAuth(); if (loading) return
Loading…
; if (!user) return ; if (!user.is_admin) return ; return children; }; const Shell = ({ children }) => { const { user } = useAuth(); const { active } = useProfile(); const loc = useLocation(); const hideChrome = loc.pathname.startsWith("/watch") || loc.pathname === "/login" || loc.pathname === "/register" || loc.pathname === "/profile"; return ( <> {!hideChrome && user && active && } {children} ); }; const RootRedirect = () => { const { user, loading } = useAuth(); const { active, loading: pl } = useProfile(); if (loading || pl) return
Loading…
; if (!user) return ; if (!active) return ; return ; }; function App() { return (
} /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } />
); } export default App;