我遇到的问题如下。我正在尝试使用auth / angular2-jwt从本地存储中获取令牌。我在app模块中创建了一个函数来获取令牌。我还导入了该模块并为root添加了它,以便确定何时获取令牌。但是,在我登录并重定向到页面后,该令牌不存在。我有Bearer的Authorization标头(并且缺少令牌)
这是我的代码。
应用模块
// we use this function to use it in the jwtmodule
// Any request will have this automatically added
export function tokGetter() {
return localStorage.getItem('token');
}
imports: [
BrowserModule,
HttpClientModule,
FormsModule,
BsDropdownModule.forRoot(),
RouterModule.forRoot(appRoutes), // we add our routes
JwtModule.forRoot({
config: {
tokenGetter: tokGetter,
whitelistedDomains: ['https://localhost:44378'],
blacklistedRoutes: ['https://localhost:44378/api/auth'] // This is the only place we dont want the token to be sent
}
})
]
这是怎么回事?有什么想法吗?