Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auth0 Angular2+ ParseHash with error handling of rules
public handleAuthentication(): void {
this.auth0.parseHash({}, (err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
this.localLogin(authResult);
this.auth0.client.userInfo(authResult.accessToken, function (err, user) {
localStorage.setItem("user_id", user.sub);
});
this.router.navigate(['/home']);
} else if (err) {
console.log(err);
// Handle unauthorized errors
if (err.error === "unauthorized" ){
console.log("Got an error from Auth0 in Hash fragment");
// Show error to user
}
this.router.navigate(['/home']);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment