import {Link, Route, Routes, useLocation, useNavigate} from 'react-router-dom'; import {useTranslation} from 'react-i18next'; import {useEffect, useState} from 'react'; import LandingPage from './pages/LandingPage'; import LoginPage from './pages/LoginPage'; import ImprintPage from './pages/ImprintPage'; import Dashboard from "./pages/Dashboard.jsx"; import RegistrationPage from './pages/RegistrationPage.jsx'; import SettingsPage from './pages/SettingsPage.jsx'; import AdminHintsPage from './pages/AdminHintsPage.jsx'; import AdminUsersPage from './pages/AdminUsersPage.jsx'; import GameLibrary from './pages/GameLibrary.jsx'; import GameDetail from './pages/GameDetail.jsx'; import WishlistPage from './pages/WishlistPage.jsx'; import PlayNextPage from './pages/PlayNextPage.jsx'; import StatsPage from './pages/StatsPage.jsx'; import ImportPage from './pages/ImportPage.jsx'; import PublicProfilePage from './pages/PublicProfilePage.jsx'; import AppHeader from './components/AppHeader.jsx'; import {Toaster} from '@/components/ui/sonner'; import {TooltipProvider} from '@/components/ui/tooltip'; import PageBackground from './components/PageBackground.jsx'; import {usePreferences} from './context/PreferencesContext.jsx'; import {clearSession, hasSession} from './utils/auth.js'; import {logout} from './utils/api.js'; function App() { const {t} = useTranslation(); const [isAuthenticated, setIsAuthenticated] = useState(false); const {appearance, syncPreferences, resetAppearance} = usePreferences(); // Hooks for routing const navigate = useNavigate(); const location = useLocation(); useEffect(() => { // No local expiry check here: a 401 from the backend ends the session (useSessionExpired), and a browser // clock that runs ahead would otherwise end it silently. setIsAuthenticated(hasSession()); }, [location]); // On login and on page load; the cached look shows until Auth answers. useEffect(() => { if (isAuthenticated) syncPreferences(); }, [isAuthenticated, syncPreferences]); // Waits for Auth: a late logout answer would clear the cookies of a login that came after it. const handleLogout = async () => { await logout(); clearSession(); resetAppearance(); setIsAuthenticated(false); navigate('/login'); }; return ( {/* isolate: the background layer sits behind the content but in front of this div's own background. */}
{/* A public profile shows the owner's background instead. */} {isAuthenticated && !location.pathname.startsWith('/u/') && }
}/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/>
{t('IMPRINT.TITLE')}
); } export default App;