| 1 | import { Navigate, Route, Routes } from "react-router-dom";
|
|---|
| 2 | import { clearAuthSession, getAuthToken, isTokenExpired } from "./utils/authSession";
|
|---|
| 3 |
|
|---|
| 4 | import LandingPage from "./pages/LandingPage/LandingPage.jsx";
|
|---|
| 5 | import Login from "./pages/Login/Login.jsx";
|
|---|
| 6 | import Register from "./pages/Register/Register.jsx";
|
|---|
| 7 | import DashboardLayout from "./pages/Dashboard/DashboardLayout.jsx";
|
|---|
| 8 | import ControlCenter from "./pages/Dashboard/pages/ControlCenter/ControlCenter.jsx";
|
|---|
| 9 | import Training from "./pages/Dashboard/pages/Training/Training.jsx";
|
|---|
| 10 | import TrainingTracking from "./pages/Dashboard/pages/Training/TrainingTracking.jsx";
|
|---|
| 11 | import NewTrainingSession from "./pages/Dashboard/pages/Training/NewTrainingSession.jsx";
|
|---|
| 12 | import Weight from "./pages/Dashboard/pages/Weight/Weight.jsx";
|
|---|
| 13 | import WeightTracking from "./pages/Dashboard/pages/Weight/WeightTracking.jsx";
|
|---|
| 14 | import NewWeightIntake from "./pages/Dashboard/pages/Weight/NewWeightIntake.jsx";
|
|---|
| 15 | import Finance from "./pages/Dashboard/pages/Finance/Finance.jsx";
|
|---|
| 16 | import FinanceTracking from "./pages/Dashboard/pages/Finance/FinanceTracking.jsx";
|
|---|
| 17 | import NewIncome from "./pages/Dashboard/pages/Finance/NewIncome.jsx";
|
|---|
| 18 | import Investing from "./pages/Dashboard/pages/Investing/Investing.jsx";
|
|---|
| 19 | import InvestingTracking from "./pages/Dashboard/pages/Investing/InvestingTracking.jsx";
|
|---|
| 20 | import NewInvestment from "./pages/Dashboard/pages/Investing/NewInvestment.jsx";
|
|---|
| 21 | import Discipline from "./pages/Dashboard/pages/Discipline/Discipline.jsx";
|
|---|
| 22 | import DisciplineTracking from "./pages/Dashboard/pages/Discipline/DisciplineTracking.jsx";
|
|---|
| 23 | import CustomCategoryKanban from "./pages/Dashboard/pages/CustomCategory/CustomCategoryKanban.jsx";
|
|---|
| 24 |
|
|---|
| 25 | function 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 |
|
|---|
| 35 | function 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 |
|
|---|
| 77 | export default App;
|
|---|