为了账号安全,请及时绑定邮箱和手机立即绑定

AuthGuard 在星云中总是错误的

AuthGuard 在星云中总是错误的

呼如林 2022-05-26 15:34:26
我使用 ngx admin 创建使用 nebular 的管理面板,我按照这个文档添加 authGard:docs这可以自定义登录:docs2所有的事情都是真实的,我得到了成功的信息:但我在 autogard 中弄错了:我使用的代码:@NgModule({  declarations: [    AppComponent,  ],  providers: [    AuthGuard,  ],  imports: [    ***  ],  bootstrap: [AppComponent],})export class AppModule {}//**********@Injectable()export class AuthGuard implements CanActivate {  constructor(private authService: NbAuthService, private router: Router) {  }  canActivate() {    console.log(this.authService.isAuthenticated());    return this.authService.isAuthenticated()      .pipe(        tap(authenticated => {          if (!authenticated) {            console.log(authenticated);            this.router.navigate(['auth/login']);          }        }),      );  }}//**********const routes: Routes = [  {    path: 'pages',    canActivate: [AuthGuard],    loadChildren: () => import('./pages/pages.module')      .then(m => m.PagesModule),  },  {    path: 'auth',    loadChildren: () => import('./auth/auth.module').then(m => m.NgxAuthModule),  },  { path: '', redirectTo: 'pages', pathMatch: 'full' },  { path: '**', redirectTo: 'pages' },];
查看完整描述

1 回答

?
慕哥6287543

TA贡献1831条经验 获得超10个赞

问题解决了。

文件说响应应该是这样的:


{

data: {

 token: 'some-jwt-token'

  } 

}

我的回答是:


{

data: {

  access_token: 'some-jwt-token'

  }

}

在文档中写道,我们可以将(令牌)更改为其他类似的东西:


 token: {

           key: 'access_token', // this parameter tells where to look for the token

         }

但这不是真的,我们应该在 NbAuthModule.forRoot 中使用它:


 token: {

           key: 'data.access_token',

         }


查看完整回答
反对 回复 2022-05-26
  • 1 回答
  • 0 关注
  • 131 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号