angular2-jwt中的AuthHttp类不存在于’npm i @ auth0 / angular-jwt’中

前端之家收集整理的这篇文章主要介绍了angular2-jwt中的AuthHttp类不存在于’npm i @ auth0 / angular-jwt’中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经安装了@ auth0 / angular-jwt软件包,并且在Anular2-jwt中有一个名为AuthHttp的类(它将自动添加Bearer并同样设置为Authorization标头).

我们如何用@ auth0 / angular-jwt实现同样的目标

解决方法

AuthHttp不再是这个模块,但你可以用@ auth0 / angular-jwt实现类似的行为.尝试将此配置添加到您的应用模块:

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 { }

有关详细信息,请参阅here.

猜你在找的Angularjs相关文章