NbAuthJWTToken is undefined after successful login
我正在使用具有自定义登录名的ngx-admin。使用API??成功登录后,控件将重定向到仪表板,但未定义NbAuthJWTToken。当我刷新页面时,页面显示错误而不重新加载页面。我该如何解决?请帮我。
NbAuthJWTToken未定义
刷新页面时出错
password-strategy-options.ts [auth / strategies / password /]
1 2 3 4 5 6 7 8 9 | token?: NbPasswordStrategyToken = { class: NbAuthJWTToken, //class: NbAuthSimpleToken, key: 'data.token', getter: (module: string, res: HttpResponse<Object>, options: NbPasswordAuthStrategyOptions) => getDeepFromObject( res.body, options.token.key, ), }; |
auth-guard.service.ts [app.module.ts附近]
1 2 3 4 5 6 7 8 9 10 11 12 13 | export class AuthGuardService implements CanActivate { constructor(private authService: NbAuthService, private router: Router) { } canActivate() { return this.authService.isAuthenticated() .pipe( tap(authenticated => { if (!authenticated) { this.router.navigate(['/login']); } }), ); } } |
app.module.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | @NgModule({ declarations: [AppComponent], imports: [.......... NbAuthModule, NbAuthModule.forRoot({ strategies: [ NbPasswordAuthStrategy.setup({ name: 'email', baseEndpoint: 'api/', login: { endpoint: 'login', }, token: { class: NbAuthJWTToken, key: 'token', } }), ], forms: {}, }), ], bootstrap: [AppComponent], providers: [ { provide: APP_BASE_HREF, useValue: '/' }, AuthGuardService, ], }) |
app-routing.module.ts
1 2 3 4 5 6 7 | const routes: Routes = [ { path: 'pages', canActivate: [AuthGuardService], loadChildren: 'app/pages/pages.module#PagesModule' }, ] |
在ng-admin中,成功登录意味着服务器以100 http代码响应。又名没有错误。因此,如果您发送没有令牌的空响应,它将仍然登录。我相信它在发送时找不到令牌,因为它的设置不正确。请分享您的资源。