0

Good Morning, I am using ReactJs and the Auth0 API. I make a GET call which gets a password change URL generated by the API and then redirects the user to that URL. Once Redirected if I hit the back button the browser it just keeps redirecting me until the URL expires. I am using react-router-dom. The redirect should only happen once.

  async function fetchPasswordURL() {
  
  const fetchURL = `http://localhost:8080/redirect`;

  const fetchConfig = {
    method: 'get',
    url: fetchURL,
  };

  const testResponse = await axios(fetchConfig);
  
  // If the response from the server is a url that is not an empty string then it runs the redirect
  if(testResponse.data != '') {

     // redirects to URL from server
     window.location.href = testResponse.data;
    
  } else {
    fetchPasswordURL()
  }
}
AS10
  • 271
  • 1
  • 15
  • any particular reason that you are not disabling back navigation when user returns from some external sensitive page like this? More : https://stackoverflow.com/questions/42831685/disable-back-button-in-react-navigation I am curious to know what do you mean by redirect should only happen once ? – Yash Kumar Verma Jun 04 '21 at 16:12
  • The URL is fetched from the backend, the redirect is executed but if the user hits the back button on the browser it redirects them again back to the URL that was fetched from the backend. I am trying to limit it that if they go back to the app from the URL it should not redirect again – AS10 Jun 04 '21 at 16:20

0 Answers0