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 {usePreferences} from './context/PreferencesContext.jsx'; function App() { const {t, i18n} = useTranslation(); const {isDarkMode, setDarkMode, setLanguage} = usePreferences(); const [isAuthenticated, setIsAuthenticated] = useState(false); // Hooks for routing const navigate = useNavigate(); const location = useLocation(); useEffect(() => { const token = localStorage.getItem('tbp_jwt'); setIsAuthenticated(!!token); // Converts the token string (or null) to a boolean }, [location]); const toggleLanguage = () => { setLanguage(i18n.language === 'de' ? 'en' : 'de'); }; const handleLogout = () => { localStorage.removeItem('tbp_jwt'); setIsAuthenticated(false); navigate('/login'); }; return (
Game Log
{isAuthenticated ? ( <> ) : ( {t('MAIN.LOGIN')} )}
}/> }/> }/> }/> }/> }/>
); } export default App;