angular - 广播服务不适用于角度的“MSAL”
问题描述
我正在努力整合 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 中添加了这段代码
你能告诉我我做错了什么吗?
解决方案
我遇到过同样的问题。我有单独的服务来执行我放置广播服务订阅代码的身份验证。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();
}
推荐阅读
- amazon-ec2 - Swapon --show 调整磁盘大小时不更新 gb 大小
- c# - 将列映射到 Dapper 中的数组
- java - IntelliJ Java 配置
- r - foreach 实现崩溃并在 R 中生成错误
- python - 删除所有布尔列都为 False 的行 - Python
- python - np.argamx 不返回整数
- powershell - 使用 PowerShell 从网页按钮单击下载文件
- python - 如何将元组保存到python中的excel
- python - 如何修复 Django 和 Postgres SQL 中布尔类型的无效输入语法:“abc”?
- reactjs - 此表达式不可调用。类型“{}”没有调用签名。TS2349