import { useSession , signIn } from "next-auth/react" ; import { useEffect } from "react" ; import router from "next/router" ; import Loader from "@lib/components/Loader" ; function WithAuth ( { children , options } ) { const { data : session , status } = useSession ( ) ; const isUser = ! ! session ?. user ; useEffect ( ( ) => { if ( status === "loading" ) { return ; } if ( ! isUser ) { if ( options ?. redirectTo ) { router . push ( options . redirectTo ) ; } else { signIn ( ) ; } } } , [ isUser , status ] ) ; if ( isUser ) { return children ; } return ( < div className = "h-screen w-screen flex flex-col justify-center content-center items-center" > < Loader className = "h-6 w-6" / > < /div>); } export default WithAuth ;