import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
return (
<button type="button" onClick={() => router.back()}>
Click here to go back
</button>
)
}
//if user not logged in
if (!auth.user) {
window.localStorage.setItem("path", router.asPath); //save current route
router.replace("/login"); //send user to login page
return <div> redirecting to login... </div>
}
//when user login
if (auth.user) {
const path = localStorage.getItem("path")
router.replace(path || "/"); //navigate to last route
return <div> Loading... </div>
);
}