I am getting following error when there is no token available and want to request server using HttpClient service:
TypeError: Cannot read property 'split' of null
Angular v4.3.1
angular-jwt v1.0.0-beta.2
@lekhnath token decode has problem.
@lekhnath which version of angular2-jwt are you using?
@chenkie I've mentioned both angular and angular-jwt version above.
having same issue.
decodeToken() should first check if there is token before decoding it (split, etc).
Or at least in the interceptor
same issue...
Fixed in 1.0.0-beta.3. There's also a new config value, throwNoTokenError which will optionally throw and error if no token exists. Defaults to false.
We might also look at using an upstream interceptor to handle stuff like this. cc @escardin
@chenkie would you update also readme? Seems like this line no longer work.
JwtModule.forRoot({
config: {
tokenGetter: () => {
return localStorage.getItem('access_token');
},
whitelistedDomains: ['localhost:3001']
}
})
providing throwNoTokenError: false option to module configuration fixed the issue in 1.0.0-beta.3.
Thanks.
This is config. Maybe we can add on readme.
import { JwtModule } from '@auth0/angular-jwt';
import { HttpClientModule } from '@angular/common/http';
Get token
export function getToken() {
return localStorage.getItem('currentUser');
}
Import Jwt Module
JwtModule.forRoot({
config: {
throwNoTokenError: false,
tokenGetter: getToken,
whitelistedDomains: ['localhost:4567']
}
}),
Most helpful comment
This is config. Maybe we can add on readme.
Get token
Import Jwt Module