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
RevLine 
[3ebe47c]1import { Navigate, Route, Routes } from "react-router-dom";
[42da64d]2import { clearAuthSession, getAuthToken, isTokenExpired } from "./utils/authSession";
[3ebe47c]3
[793ce2c]4import LandingPage from "./pages/LandingPage/LandingPage.jsx";
[3ebe47c]5import Login from "./pages/Login/Login.jsx";
6import Register from "./pages/Register/Register.jsx";
[8c01a1f]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";
[708af9e]13import WeightTracking from "./pages/Dashboard/pages/Weight/WeightTracking.jsx";
14import NewWeightIntake from "./pages/Dashboard/pages/Weight/NewWeightIntake.jsx";
[8c01a1f]15import Finance from "./pages/Dashboard/pages/Finance/Finance.jsx";
[8449b9c]16import FinanceTracking from "./pages/Dashboard/pages/Finance/FinanceTracking.jsx";
17import NewIncome from "./pages/Dashboard/pages/Finance/NewIncome.jsx";
[8c01a1f]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";
[4f85b41]22import DisciplineTracking from "./pages/Dashboard/pages/Discipline/DisciplineTracking.jsx";
[e9a0543]23import CustomCategoryKanban from "./pages/Dashboard/pages/CustomCategory/CustomCategoryKanban.jsx";
[3ebe47c]24
25function RequireAuth({ children }) {
[42da64d]26 const token = getAuthToken();
27 if (token && isTokenExpired(token)) {
28 clearAuthSession();
29 return <Navigate to="/login" replace />;
30 }
[3ebe47c]31 if (!token) return <Navigate to="/login" replace />;
32 return children;
33}
[72053b5]34
35function App() {
[3ebe47c]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>
[8c01a1f]46 <DashboardLayout />
[3ebe47c]47 </RequireAuth>
48 }
[8c01a1f]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 />} />
[708af9e]59 <Route path="weight/tracking" element={<WeightTracking />} />
60 <Route path="weight/intakes/new" element={<NewWeightIntake />} />
[8c01a1f]61 <Route path="finance" element={<Finance />} />
[8449b9c]62 <Route path="finance/tracking" element={<FinanceTracking />} />
63 <Route path="finance/incomes/new" element={<NewIncome />} />
[8c01a1f]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 />} />
[4f85b41]68 <Route path="discipline/tracking" element={<DisciplineTracking />} />
[e9a0543]69 <Route path="custom/:customTrackingId" element={<CustomCategoryKanban />} />
[8c01a1f]70 </Route>
[3ebe47c]71 <Route path="*" element={<Navigate to="/" replace />} />
72 </Routes>
73 </div>
74 );
[72053b5]75}
76
[44a42b8]77export default App;
Note: See TracBrowser for help on using the repository browser.