source: imaps-frontend/src/components/ProtectedRoute/ProtectedRoute.jsx@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 755 bytes
RevLine 
[0c6b92a]1import { Navigate, Outlet, useLocation } from "react-router-dom";
2import {useAppContext} from "../AppContext/AppContext.jsx";
3import HttpService from "../../scripts/net/HttpService.js";
4import React, {useEffect} from "react";
5import {LoadingContainer} from "../LoadingContainer/LoadingContainer.jsx";
6import config from "../../scripts/net/netconfig.js";
7import {verifyToken} from "../../scripts/util/verifyToken.js";
[d565449]8
[0c6b92a]9const 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 />;
[d565449]24};
25
26export default ProtectedRoute;
Note: See TracBrowser for help on using the repository browser.