This is for the v1.0 branch -- it is a known issue that lambda expressions won't work when compiling with Webpack for AOT as that process reguires named exported functions. Thus this line in jwt.interceptor.ts and jwt.interceptor.d.ts causes an error:
tokenGetter?: () => string | Promise
The error at runtime is
this.tokenGetter is not a function.
A work-around is to replace the lambda expression with a named exported function. I'm not sure how that would work in a d.ts file, hopefully you can figure that out. Thanks.
I'm facing
same problem
Can someone help us please


I fixed it like this
export function getAccessToken() {
return localStorage.getItem('access_token');
}
JwtModule.forRoot({
config: {
tokenGetter: (getAccessToken),
whitelistedDomains: ['localhost:44314']
}
})
okay cool!
i will check out on morning and let you know,
if works on my side.
cool, just remember to change the whitelistedDomains in the example I pasted
okay cool!
Thanks for your suggestion -- interesting idea to use a string. Alas I'm still getting this error when I try it:
TypeError: this.tokenGetter is not a function
at JwtInterceptor.intercept (vendor.bundle.js:1)
at HttpInterceptorHandler.handle (
I should clarify that this is at run time. I'm not seeing the compile time error referenced above.
@jculverwell's solution didn't work for me either. It gives me this.tokenGetter is not a function.
@chenkie do you have a solution for this?
This worked ok for me, in same module:
Before module declaration:
export function getJwtToken(): string {
return localStorage.getItem("access_token");
}
Module imports config:
JwtModule.forRoot({
config: {
tokenGetter: getJwtToken,
whitelistedDomains: ['localhost:8000']
}
})
Angular 4.3.6
@auth0/angular-jwt 1.0.0-beta.9
Without a return type declaration the build wasn't passing for me.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇♂️
Most helpful comment
I fixed it like this