Skip to content

Instantly share code, notes, and snippets.

@ShayMe21
Created May 16, 2019 22:10
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/0d08a375287ba3d24f09264684432f43 to your computer and use it in GitHub Desktop.
Save ShayMe21/0d08a375287ba3d24f09264684432f43 to your computer and use it in GitHub Desktop.
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