【问题标题】:broadcast service not working with 'MSAL' in angular广播服务不适用于角度的“MSAL”
【发布时间】:2020-04-27 14:09:14
【问题描述】:

我正在努力集成 MSAL 服务。我遇到了广播服务的问题。

 this.broadcastService.subscribe('msal:loginSuccess', async () => {
      //this.checkoutAccount();
      console.info('msal:login');
      console.info(this.authService.getAccount);
      console.info(this.authService.getRedirectUri);
    });

我看到在本地存储中我可以看到令牌,但是当我尝试订阅上述代码时,它没有进入,也没有抛出任何错误。

我需要登录成功。

我也在 app.component.ts 中添加了这段代码

你能告诉我我做错了什么吗?

【问题讨论】:

    标签: angular


    【解决方案1】:

    我有同样的问题。我有单独的服务来执行我放置广播服务订阅代码的身份验证。 login-success 从未被解雇。事实证明,您只需在根组件(app.component)订阅广播服务。请检查您是否从多个地方订阅。

    如果您需要将订阅代码放在 app.component 之外的单独服务中,您可以使用服务内部的订阅代码创建 initialize() 函数,并从 app.component init() 调用它。这对我有用。

    AuthenticationServicet.ts:

    initialize() {
      this._broadcastService.subscribe('msal:loginSuccess', (x) => {
        console.log("login success.");
        alert("success");
      });
    }
    

    app.component.ts:

    ngOnInit() {
        this._authenticationService.initialize();
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-25
      • 1970-01-01
      • 2018-01-08
      • 2021-12-07
      • 1970-01-01
      • 2020-11-03
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多