Created
May 16, 2019 22:10
-
-
Save ShayMe21/0d08a375287ba3d24f09264684432f43 to your computer and use it in GitHub Desktop.
Auth0 Angular2+ ParseHash with error handling of rules
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) { | |
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