Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/src/components/ProtectedRoute/ProtectedRoute.jsx
rd565449 r0c6b92a 1 import React from "react"; 2 import { Outlet, Navigate } from "react-router-dom"; 1 import { Navigate, Outlet, useLocation } from "react-router-dom"; 2 import {useAppContext} from "../AppContext/AppContext.jsx"; 3 import HttpService from "../../scripts/net/HttpService.js"; 4 import React, {useEffect} from "react"; 5 import {LoadingContainer} from "../LoadingContainer/LoadingContainer.jsx"; 6 import config from "../../scripts/net/netconfig.js"; 7 import {verifyToken} from "../../scripts/util/verifyToken.js"; 3 8 4 const ProtectedRoute = ({ isAuthenticated }) => { 5 return isAuthenticated ? <Outlet /> : <Navigate to="/Login" />; 9 const ProtectedRoute = () => { 10 const location = useLocation(); 11 const {loading,isAuthenticated} = useAppContext(); 12 13 14 if(loading){ 15 return <LoadingContainer/> 16 } 17 18 19 if (!isAuthenticated) { 20 return <Navigate to="/Login" state={{ targetPath: location }} replace />; 21 } 22 23 return <Outlet />; 6 24 }; 7 25
Note:
See TracChangeset
for help on using the changeset viewer.