import { FC , useContext } from "react" ; import { Navigate , useLocation } from "react-router-dom" ; import { AppContext } from "../../store/app-context" ; type Props = { children : JSX . Element ; } ; const RequireAuth = ( { children } ) => { let { isLoggedIn } = useContext ( AppContext ) ; let location = useLocation ( ) ; if ( ! isLoggedIn ) { return < Navigate to = "/login" state = { { from : location } } replace / > ; } return children ; } ; export default RequireAuth ;