0

Hey guys suppose my application has a verification page which is used to verify the user after registration, I want to prevent user from accessing this route manually and it should only be accessible by navigating the user from registration page . how can i check on verification page that user came here from registration page and if not then redirect it to registration page again. Something like most web application does, for verifying users email. Do they store something in local-storage /sessions or pass something inside query parameters.

For example like on uber when i put my email it sends a verification code on my email with the link and navigates me to a verification page from registration page. But am not able to come to this page manually so its preventing me. If anyone can help , it will be great.

enter image description here enter image description here

I have made the registration and login page , and setup all the routing but i have this doubt.

aditya rawat
  • 35
  • 2
  • 5
  • I solved this buy getting the information about if the registered user is verified. if the user is registered and verified, he is not able to access this page. you could also pass a state from your to the component and check for that. and: if (location.state?.from !== 'register') {… – JohnDole Mar 05 '23 at 23:22
  • @JohnDole can't we pass state with useNavigate() hook . – aditya rawat Mar 06 '23 at 13:01

1 Answers1

0

I guess you can use an useEffect with some logic that if a query param is not met you can just push it to other page like homepage

something like this

 useEffect(()=>{

  if( some param not met ){

    Router.push("/")
  }

 })
murdock_
  • 3
  • 2