【问题标题】:OktaAuth not working when used in Angualr site在 Angular 站点中使用时,Okta Auth 不起作用
【发布时间】:2021-12-02 12:42:33
【问题描述】:

在我的 Angular 应用程序中,我有这个功能可以直接进入登录页面:

const oktaConfig = Object.assign({
  onAuthRequired: (oktaAuth: any, injector: { get: (arg0: any) => any; }) => {
    const router = injector.get(Router);

    // redirect the user to your custom login page
    router.navigate('/login');
  }
}, myAppConfig.oidc);

我的一条路线如下:

const routes: Routes = [
  { path: 'members', component: MembersPageComponent, canActivate: [ OktaAuthGuard ] },
...
];

我的 login.status.component.html 包含:

<button routerLink="/members" class="security-btn ml-1">Member</button>

单击“成员”按钮时,如果用户尚未登录,则应将其定向到登录页面。在我的应用程序中,如果这样做,页面上不会发生任何可见的事情,但控制台会出现此错误:

ERROR Error: Uncaught (in promise): TypeError: commands.reduce is not a function computeNavigation@http://localhost:4200/vendor.js:53359:26 createUrlTree@http://localhost:4200/vendor.js:53291:34 createUrlTree@http://localhost:4200/vendor.js:56121:16 导航@http://localhost:4200/vendor.js:56190:40 onAuthRequired@http://localhost:4200/main.js:160:16 handleLogin/

我认为我的问题与我在函数中传递参数的方式有关。我这样做是否正确,如果正确,我做错了什么?

【问题讨论】:

    标签: javascript angular typescript okta okta-api


    【解决方案1】:

    router.navigate('/login'); 应该是 router.navigate(['/login']);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2023-02-23
      • 2013-08-04
      • 1970-01-01
      • 2021-01-22
      • 2020-06-04
      • 2021-05-08
      相关资源
      最近更新 更多