Created
August 21, 2019 21:46
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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