Skip to content

Instantly share code, notes, and snippets.

@ShayMe21
Created March 11, 2019 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShayMe21/1f41a0c7e37c6d5488b69d4506603a33 to your computer and use it in GitHub Desktop.
Save ShayMe21/1f41a0c7e37c6d5488b69d4506603a33 to your computer and use it in GitHub Desktop.
Auth0.js ParseHash detect state missing error check and redirect. This can happen when a user bookmarks the hosted login page or keeps the page open for 30minutes+
public handleAuthentication(): void {
this.auth0.parseHash({
}, (err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
console.log(authResult);
this.localLogin(authResult);
this.auth0.client.userInfo(authResult.accessToken, function (err, user) {
localStorage.setItem("user_id", user.sub);
console.log(user.sub);
console.log(user);
});
this.router.navigate(['/home']);
} else if (err) {
console.log(err);
if (err.error == "invalid_token" && err.errorDescription == "`state` does not match."){
console.log("Invalid token, state does not match error... ");
this.router.navigate(['/home']);
}
//alert(`Error: ${err.error}. Check the console for further details.`);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment