React SDK and auth0js error

I have a React App using Auth0. I basically copy and pasted the code from the quickstart into it. This piece of code no longer works:

    handleAuthentication() {
        this.auth0.parseHash((err, authResult) => {
          if (authResult && authResult.accessToken && authResult.idToken) {
            this.setSession(authResult);
            history.replace('/');
          } else if (err) {
            history.replace('/');
            console.log(err);
            alert(`Error: ${err.error}. Check the console for further details.`);
          }
        });
      }

Whenever I try to log in I get an error message “invalid_token. “Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.”
But when I comment out the 'history.replace(”/")’ line in the error handler it works. I get the error pop-up initially but then it goes back and gets the token. I’m not sure what to make of this.

Having the same problem.

After digging into my own code for a bit which looks pretty similar, I realized that the problem we’re facing is not CORS but the async error i.e. the page is being unloaded.

I’m guessing setSession is doing some async operation in ur code, likely an XHR such as getUserInfo thus because we’re switching routes before that async operation is completed it’s cancelling the request I believe or the ability to receive the response due to a switch in origins (or referrers).

@ stephenhuh So… How can I fix this?

@woeterman_94 basically dont switch pages until the Auth0 is done doing its thing.