Untitled
unknown
javascript
2 years ago
596 B
13
Indexable
import { useAuthenticationStatus } from "@nhost/react"; import { Navigate, useLocation } from "react-router-dom"; const ProtectedRoute = ({ children }) => { const { isAuthenticated, isLoading } = useAuthenticationStatus(); const location = useLocation(); if (isLoading) { console.log("protected inside", isAuthenticated); return ( <div> <p>Please wait....</p> </div> ); } if (!isAuthenticated) { return <Navigate to="/login" state={{ from: location }} replace />; } return children; }; export default ProtectedRoute;
Editor is loading...