Auth0 Home Blog Docs

Angular quickstart incompatible with latest version of angular2-jwt

angular-2
quickstart
angular2-jwt

#1

The documentation for the quick-start with Angular 2 - Section Login - contains the following errors:

localStorage.setItem('id_token', authResult.idToken);

// ...

public authenticated() {
     // Check if there's an unexpired JWT
     // This searches for an item in localStorage with key == 'id_token'
     return tokenNotExpired();   
}

This code does not work correctly with angular2-JWT, as in the latest version (see commit) the default key for token in localStorage is ‘token’, neither ‘id_token’ (as written here) nor ‘access_token’ (as in angular2-jwt previous commit).


#2

A simple fix for the quickstart would be:

localStorage.setItem('token', authResult.idToken);

The previous content was provided by @lettau.ralph in the question body itself, I’m providing it as an answer for discoverability reasons.


#3

@lettau.ralph I reported this issue internally; I also added your original workaround as an answer so that other people find it easier to locate. If you want you can add that as your own answer and I’ll later delete mine. Thanks for reporting this situation.


#4