mksmanjit
mksmanjit

Reputation: 244

AuthHttp class in angular2-jwt not present in 'npm i @auth0/angular-jwt'

I have installed the @auth0/angular-jwt package and as in Anular2-jwt there is class called AuthHttp(which will add Bearer automatically and also set into the Authorization header as well).

How can we achieve the same thing with @auth0/angular-jwt

Upvotes: 5

Views: 1224

Answers (1)

eduPeeth
eduPeeth

Reputation: 1868

AuthHttp is no more in this module but you can achieve similar behavior with @auth0/angular-jwt. Try adding this configuration to you app module :

import { JwtModule } from '@auth0/angular-jwt';
...

export function tokenGetter() {
  return localStorage.getItem('access_token');
}

@NgModule({
...

JwtModule.forRoot({
      config: { tokenGetter: tokenGetter,
      whitelistedDomains: ['http://localhost:8080'],
      blacklistedRoutes: [],
      headerName: 'x-auth-token',
      throwNoTokenError: true,
      skipWhenExpired: false,
      authScheme:'name of auth scheme' //default is Bearer  
}
    })
....
})
export class AppModule { }

For more details refer here.

Upvotes: 1

Related Questions