source: frontend/src/App.jsx

Last change on this file was 42da64d, checked in by Andrej <asumanovski@…>, 8 weeks ago

Fixed auth issue

  • Property mode set to 100644
File size: 3.7 KB
Line 
1import { Navigate, Route, Routes } from "react-router-dom";
2import { clearAuthSession, getAuthToken, isTokenExpired } from "./utils/authSession";
3
4import LandingPage from "./pages/LandingPage/LandingPage.jsx";
5import Login from "./pages/Login/Login.jsx";
6import Register from "./pages/Register/Register.jsx";
7import DashboardLayout from "./pages/Dashboard/DashboardLayout.jsx";
8import ControlCenter from "./pages/Dashboard/pages/ControlCenter/ControlCenter.jsx";
9import Training from "./pages/Dashboard/pages/Training/Training.jsx";
10import TrainingTracking from "./pages/Dashboard/pages/Training/TrainingTracking.jsx";
11import NewTrainingSession from "./pages/Dashboard/pages/Training/NewTrainingSession.jsx";
12import Weight from "./pages/Dashboard/pages/Weight/Weight.jsx";
13import WeightTracking from "./pages/Dashboard/pages/Weight/WeightTracking.jsx";
14import NewWeightIntake from "./pages/Dashboard/pages/Weight/NewWeightIntake.jsx";
15import Finance from "./pages/Dashboard/pages/Finance/Finance.jsx";
16import FinanceTracking from "./pages/Dashboard/pages/Finance/FinanceTracking.jsx";
17import NewIncome from "./pages/Dashboard/pages/Finance/NewIncome.jsx";
18import Investing from "./pages/Dashboard/pages/Investing/Investing.jsx";
19import InvestingTracking from "./pages/Dashboard/pages/Investing/InvestingTracking.jsx";
20import NewInvestment from "./pages/Dashboard/pages/Investing/NewInvestment.jsx";
21import Discipline from "./pages/Dashboard/pages/Discipline/Discipline.jsx";
22import DisciplineTracking from "./pages/Dashboard/pages/Discipline/DisciplineTracking.jsx";
23import CustomCategoryKanban from "./pages/Dashboard/pages/CustomCategory/CustomCategoryKanban.jsx";
24
25function RequireAuth({ children }) {
26 const token = getAuthToken();
27 if (token && isTokenExpired(token)) {
28 clearAuthSession();
29 return <Navigate to="/login" replace />;
30 }
31 if (!token) return <Navigate to="/login" replace />;
32 return children;
33}
34
35function App() {
36 return (
37 <div data-theme="forest" className="min-h-screen w-full">
38 <Routes>
39 <Route path="/" element={<LandingPage />} />
40 <Route path="/login" element={<Login />} />
41 <Route path="/register" element={<Register />} />
42 <Route
43 path="/dashboard"
44 element={
45 <RequireAuth>
46 <DashboardLayout />
47 </RequireAuth>
48 }
49 >
50 <Route index element={<Navigate to="control-center" replace />} />
51 <Route path="control-center" element={<ControlCenter />} />
52 <Route path="training" element={<Training />} />
53 <Route path="training/tracking" element={<TrainingTracking />} />
54 <Route
55 path="training/sessions/new"
56 element={<NewTrainingSession />}
57 />
58 <Route path="weight" element={<Weight />} />
59 <Route path="weight/tracking" element={<WeightTracking />} />
60 <Route path="weight/intakes/new" element={<NewWeightIntake />} />
61 <Route path="finance" element={<Finance />} />
62 <Route path="finance/tracking" element={<FinanceTracking />} />
63 <Route path="finance/incomes/new" element={<NewIncome />} />
64 <Route path="investing" element={<Investing />} />
65 <Route path="investing/tracking" element={<InvestingTracking />} />
66 <Route path="investing/assets/new" element={<NewInvestment />} />
67 <Route path="discipline" element={<Discipline />} />
68 <Route path="discipline/tracking" element={<DisciplineTracking />} />
69 <Route path="custom/:customTrackingId" element={<CustomCategoryKanban />} />
70 </Route>
71 <Route path="*" element={<Navigate to="/" replace />} />
72 </Routes>
73 </div>
74 );
75}
76
77export default App;
Note: See TracBrowser for help on using the repository browser.