JwtHelperService does not work when using promise
See original GitHub issueDescription
I’m trying to use jwtOptionsFactory to handle getting token from ngrx store.
The interceptor works just fine, but when I try to us JwtHelperService
without passing token (I guess it uses tokengetter by default) or with passing token via this.jwtHelperService.tokenGetter()
does not work because my factory return promise while the method from service tries run split
method on promise, not on string…
My code:
function jwtOptionsFactory(store: Store<any>): object {
return {
whitelistedDomains: ['localhost:5500'],
tokenGetter: () => {
return store.select(FromAppState.selectAuthToken)
.pipe(take(1))
.toPromise();
}
};
}
@NgModule({
// ...
imports: [
// ...
JwtModule.forRoot({
jwtOptionsProvider: {
provide: JWT_OPTIONS,
useFactory: jwtOptionsFactory,
deps: [Store]
}
}),
// ...
]
bootstrap: [AppComponent]
})
export class AppModule {}
constructor(private dialogService: DialogService,
private jwtHelperService: JwtHelperService) { }
ngOnInit(): void {
console.log(this.jwtHelperService.tokenGetter()); // <= return promise, not string
console.log(this.jwtHelperService.decodeToken(this.jwtHelperService.tokenGetter()));
console.log(this.jwtHelperService.isTokenExpired(this.jwtHelperService.tokenGetter()));
console.log(this.jwtHelperService.getTokenExpirationDate(this.jwtHelperService.tokenGetter()));
}
error:
Please fix this
Also it would be great if this would also supports Observable
Prerequisites
- I have checked the README documentation.
- I have checked the Auth0 Community for related posts.
- I have checked for related or duplicate [Issues](https://github.com/auth0/angular2-jwt /issues) and [PRs](https://github.com/auth0/angular2-jwt /pulls).
- I have read the Auth0 general contribution guidelines.
- I have read the Auth0 Code of Conduct.
- I am reporting this to the correct repository.
Environment
Please provide the following:
- Version of angular2-jwt being used: “@auth0/angular-jwt”: “^2.1.0”,
- Version of the platform or framework used, if applicable: “@angular/core”: “~8.0.0”
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:12
Top Results From Across the Web
angular - Getting error in Jwthelperservice - Stack Overflow
I am using Visual studio code and it is not throwing any syntax error. But getting error in console : Error: StaticInjectorError(AppModule)[ ...
Read more >Developers - JwtHelperService does not work when using promise -
JwtHelperService does not work when using promise. ... I'm trying to use jwtOptionsFactory to handle getting token from ngrx store. The interceptor works...
Read more >angular-jwt-async - npm Package Health Analysis - Snyk
JSON Web Token helper library for Angular. Forked from @auth0/angular-jwt. Allows for async promises for whitelist and blacklist For more information about ...
Read more >@auth0/angular-jwt - npm
This library provides an HttpInterceptor which automatically attaches a JSON Web Token to HttpClient requests. This library does not have any ...
Read more >error ts2366: function lacks ending return statement ... - You.com
You need to return the whole Promise chain. As is, the setAdress function doesn't return anything. You should also consider fixing the spelling...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, it’s still an issue. 😦 Any luck with the fix?
I have the same problem in version 3.0. Any luck with bug fix?