Created
March 11, 2019 22:51
-
-
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+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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