-
Notifications
You must be signed in to change notification settings - Fork 477
Closed
Labels
bugclosed:staleIssue or PR has not seen activity recentlyIssue or PR has not seen activity recentlyhelp wanted
Description
Description
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()));
}
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"
maciej-sielski, vukdavid, LeandroFChaves, bleuscyther and manbearwiz
Metadata
Metadata
Assignees
Labels
bugclosed:staleIssue or PR has not seen activity recentlyIssue or PR has not seen activity recentlyhelp wanted
