Search
 
SCRIPT & CODE EXAMPLE
 

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>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: add word in string in javascript 
Javascript :: toggle 
Javascript :: print() in javascript 
Javascript :: bind jquery 
Javascript :: data table in angular 8 from api 
Javascript :: $out in mongodb 
Javascript :: swift encode json 
Javascript :: latecy discord 
Javascript :: javascript trim text 
Javascript :: react native list view 
Javascript :: concat emoji with text in react js 
Javascript :: shuffle array in javascript 
Javascript :: await fetch parameters 
Javascript :: export json / array to excel in javascript 
Javascript :: mock callback function jest 
Javascript :: d3 script 
Javascript :: add two floating point numbers jquery 
Javascript :: how to return json data from mvc controller to view 
Javascript :: looping through json array 
Javascript :: streami node js 
Javascript :: from json timestamp to date python 
Javascript :: Example Of LinkedList In JavaScript 
Javascript :: moment js 
Javascript :: angular ngstyle variable 
Javascript :: javascript export default 
Javascript :: javascript Display a Text Once After 3 Second 
Javascript :: how to sepaarte text in object javascript 
Javascript :: defining functions in react 
Javascript :: how to get form all filed with properties in jquery 
Javascript :: how to push array 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =