Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to go to last page after authentication

//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>
  );
}
 
PREVIOUS NEXT
Tagged: #page #authentication
ADD COMMENT
Topic
Name
7+4 =