DockerRegistryWebUI/src/ProtectedRoute.tsx
2022-04-11 08:50:03 +01:00

20 lines
497 B
TypeScript

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