Skip to content

Instantly share code, notes, and snippets.

@EdgarValfogo
Created August 21, 2019 21:46
Show Gist options
  • Save EdgarValfogo/8a911e5f4da0376279f56b1120eb1b11 to your computer and use it in GitHub Desktop.
Save EdgarValfogo/8a911e5f4da0376279f56b1120eb1b11 to your computer and use it in GitHub Desktop.
How to add tokenGetter to appModule. Problem solver: "Cannot read property 'tokenGetter' of undefined at new JwtInterceptor"
// Create a function that get the token from some storage
export function tokenGetter() {
console.log('token');
return localStorage.getItem('token');
}
@NgModule({
declarations: [
AppComponent,
],
imports: [
//...
JwtModule.forRoot({
config: {
tokenGetter: () => tokenGetter()
}
}),
//...
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment