Ignore:
Timestamp:
12/12/24 17:06:06 (5 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
d565449
Message:

Pred finalna verzija

File:
1 edited

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";
     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";
    38
    4 const ProtectedRoute = ({ isAuthenticated }) => {
    5   return isAuthenticated ? <Outlet /> : <Navigate to="/Login" />;
     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 />;
    624};
    725
Note: See TracChangeset for help on using the changeset viewer.