@auth0/angular-jwt is not attaching authorization headers on my API calls and I’m stuck on this for a long time now
This is my configuration:
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RouteReuseStrategy} from '@angular/router';
import {IonicModule, IonicRouteStrategy} from '@ionic/angular';
import {SplashScreen} from '@ionic-native/splash-screen/ngx';
import {StatusBar} from '@ionic-native/status-bar/ngx';
import {AppComponent} from './app.component';
import {AppRoutingModule} from './app-routing.module';
import {Storage, IonicStorageModule} from '@ionic/storage';
import {HttpClientModule} from '@angular/common/http';
import {JwtModule, JWT_OPTIONS, JwtHelperService} from '@auth0/angular-jwt';
import {InAppBrowser} from '@ionic-native/in-app-browser/ngx';
export function jwtOptionsFactory(storage) {
return {
tokenGetter: () => {
return storage.get('jwt_token');
},
whitelistedDomains: ['localhost:3000'],
throwNoTokenError: true
};
}
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,
IonicStorageModule.forRoot(),
HttpClientModule,
JwtModule.forRoot({
jwtOptionsProvider: {
provide: JWT_OPTIONS,
useFactory: jwtOptionsFactory,
deps: [Storage],
}
})],
providers: [
StatusBar,
SplashScreen,
{provide: RouteReuseStrategy, useClass: IonicRouteStrategy},
{provide: JWT_OPTIONS, useValue: JWT_OPTIONS},
JwtHelperService,
InAppBrowser
],