Auth0 Home Blog Docs

Angular parseHash returns undefined

angular
angular-2
parsehash

#1

this.auth0.parseHash((err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
window.location.hash = ‘’;
this.setSession(authResult);
this.router.navigate(’/’]);
} else if (err) {
this.router.navigate(’/’]);
}
});
However, while window.location.hash contains authResult: #access_token=qwe&expires_in=7200&token_type=Bearer&state=zbc&id_token=xyz, auth0.parseHash returns invalid token and authResult is undefined I am using : “@auth0/angular-jwt”: “^1.0.0-beta.9”,
“auth0-js”: “^9.2.2”


#2

What is the output of err that you’re getting when authResult is undefined?

Can you try:

this.auth0.parseHash((err, authResult) => { 
  if (err) {
    console.log(err);
    this.router.navigate('/']); 
  }

  else if (authResult && authResult.accessToken && authResult.idToken) { 
    window.location.hash = ''; 
    this.setSession(authResult); 
    this.router.navigate('/']); 
  } 
});