12 lines
363 B
TypeScript
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; |