亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 119 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號