Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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