This repository has been archived on 2022-05-20. You can view files and clone it, but cannot push or open issues or pull requests.
Alley-HSBC-Frontend/src/ProtectedRoute.tsx
2022-03-11 08:45:17 +00:00

12 lines
363 B
TypeScript

import { useLocation, Outlet, Navigate } from "react-router-dom";
import useAuth from "./hooks/useAuth";
const ProtectedRoute = () => {
const { auth }: any = useAuth();
const location = useLocation();
return (
auth?.isLoggedIn ? <Outlet /> : <Navigate to="/login" state={{ from: location }} replace />
);
}
export default ProtectedRoute;