feat: add secure login page with jwt authentication and button animation
This commit is contained in:
15
src/App.tsx
15
src/App.tsx
@@ -1,16 +1,27 @@
|
||||
import { Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
|
||||
import Layout from './components/Layout';
|
||||
import Dashboard from './pages/Dashboard';
|
||||
import Products from './pages/Products';
|
||||
import ProductDetails from './pages/ProductDetails';
|
||||
import Clients from './pages/Clients';
|
||||
import ClientDetails from './pages/ClientDetails';
|
||||
import Login from './pages/Login';
|
||||
import { isAuthenticated } from './dataService';
|
||||
|
||||
function PrivateRoute({ children }: { children: JSX.Element }) {
|
||||
const location = useLocation();
|
||||
if (!isAuthenticated()) {
|
||||
return <Navigate to="/login" state={{ from: location }} replace />;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/" element={<Navigate to="/graph" replace />} />
|
||||
<Route path="/" element={<Layout />}>
|
||||
<Route path="/" element={<PrivateRoute><Layout /></PrivateRoute>}>
|
||||
<Route path="graph" element={<Dashboard />} />
|
||||
<Route path="products" element={<Products />} />
|
||||
<Route path="products/:id" element={<ProductDetails />} />
|
||||
|
||||
Reference in New Issue
Block a user