Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

angular

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

like image 651
mksmanjit Avatar asked Nov 08 '22 04:11

mksmanjit


1 Answers

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.

like image 111
eduPeeth Avatar answered Nov 11 '22 15:11

eduPeeth