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
|
Rev | Line | |
---|
[0c6b92a] | 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";
|
---|
[d565449] | 8 |
|
---|
[0c6b92a] | 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 />;
|
---|
[d565449] | 24 | };
|
---|
| 25 |
|
---|
| 26 | export default ProtectedRoute;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.