|
Last change
on this file since 3ebe47c was 3ebe47c, checked in by Andrej <asumanovski@…>, 5 months ago |
|
Made authentication on frontend and backend
|
-
Property mode
set to
100644
|
|
File size:
991 bytes
|
| Line | |
|---|
| 1 | import { Navigate, Route, Routes } from "react-router-dom";
|
|---|
| 2 |
|
|---|
| 3 | import LandingPage from "./pages/LandingPage/LandingPage.jsx";
|
|---|
| 4 | import Login from "./pages/Login/Login.jsx";
|
|---|
| 5 | import Register from "./pages/Register/Register.jsx";
|
|---|
| 6 | import Dashboard from "./pages/Dashboard.jsx";
|
|---|
| 7 |
|
|---|
| 8 | function RequireAuth({ children }) {
|
|---|
| 9 | const token = localStorage.getItem("authToken");
|
|---|
| 10 | if (!token) return <Navigate to="/login" replace />;
|
|---|
| 11 | return children;
|
|---|
| 12 | }
|
|---|
| 13 |
|
|---|
| 14 | function App() {
|
|---|
| 15 | return (
|
|---|
| 16 | <div data-theme="forest" className="min-h-screen w-full">
|
|---|
| 17 | <Routes>
|
|---|
| 18 | <Route path="/" element={<LandingPage />} />
|
|---|
| 19 | <Route path="/login" element={<Login />} />
|
|---|
| 20 | <Route path="/register" element={<Register />} />
|
|---|
| 21 | <Route
|
|---|
| 22 | path="/dashboard"
|
|---|
| 23 | element={
|
|---|
| 24 | <RequireAuth>
|
|---|
| 25 | <Dashboard />
|
|---|
| 26 | </RequireAuth>
|
|---|
| 27 | }
|
|---|
| 28 | />
|
|---|
| 29 | <Route path="*" element={<Navigate to="/" replace />} />
|
|---|
| 30 | </Routes>
|
|---|
| 31 | </div>
|
|---|
| 32 | );
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | export default App;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.