1

我想知道是否有办法在 Ngrx 效果中使用 Msal angular 的 loginRedirect(): void 函数而不是 loginPopup(): Promise。

我可以使用 loginPopup() 但由于 loginRedirect() 的 void 返回类型,它破坏了我的 ngrx 效果链。由于移动设备上的弹出窗口问题,我无法使用 loginPopup() 函数。

下面是适用于 loginPopup() 的代码: Promise

@Effect()
  msalAuthLogin$ = this.actions$.pipe(
    ofType(MsalAuthActionTypes.Login),
    switchMap(() =>
      this.msalAuthService.loginPopup().pipe(
        map(id_token => new AcquireTokenSilent()),
        catchError(error => of(new LoginFail({ error })))
      )
    )
  );
4

2 回答 2

0

尝试像这样通过装饰器传递“{dispatch: false}”:

@Effect({dispatch: false})

在编写不分派动作的效果时,您需要明确说明它。如果不是,您的应用程序将尝试订阅和发送相同的操作 - 使您的浏览器崩溃

于 2019-05-07T20:21:25.757 回答
0

我在Start using ngrx/effects for this 中讨论了其中的一些

对话:

@Effect()
openDialog = this.actions.pipe(
  ofType(LoginActionTypes.OpenLoginDialog),
  exhaustMap(_ => {
    let dialogRef = this.dialog.open(LoginDialog);
    return dialogRef.afterClosed();
  }),
  map((result: any) => {
    if (result === undefined) {
      return new CloseDialog();
    }
    return new LoginDialogSuccess(result);
  }),
);

导航:

@Effect({ dispatch: false })
logOut = this.actions.pipe(
  ofType(ActionTypes.LogOut),
  tap([payload, username] => {
    this.router.navigate(['/']);
  })
)
于 2019-05-08T08:17:04.867 回答