Skip to content

Instantly share code, notes, and snippets.

@stephengardner
Last active December 20, 2017 12:12
Show Gist options
  • Save stephengardner/f39c24e99f26cfa5a753bab6cd146442 to your computer and use it in GitHub Desktop.
Save stephengardner/f39c24e99f26cfa5a753bab6cd146442 to your computer and use it in GitHub Desktop.
{ JwtModule } from '@auth0/angular-jwt';
import { HttpClientModule } from '@angular/common/http';
// Create a Factory for our JwtModule config since Angular doesn't allow functions in decorators.
// Also, we have to add the export keyword, otherwise Angular complains again
export function JwtModuleConfigFactory() {
return localStorage.getItem('access_token');
}
@NgModule({
bootstrap: [AppComponent],
imports: [
// ...
HttpClientModule,
JwtModule.forRoot({
config: {
tokenGetter: JwtModuleConfigFactory, // good to go!
whitelistedDomains: ['localhost:3001'] // this is just an example...
}
})
]
})
export class AppModule {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment