Reputation: 332
I am working to integrate MSAL service. I am facing issue with the broadcast service.
this.broadcastService.subscribe('msal:loginSuccess', async () => {
//this.checkoutAccount();
console.info('msal:login');
console.info(this.authService.getAccount);
console.info(this.authService.getRedirectUri);
});
I see that in local storage i can see the token but when i am trying to subscribing the above code it is not getting in and also not throwing any errors.
I need to get login success.
Also i have added this code in app.component.ts
Can you please tell what is that i am doing wrong.
Upvotes: 0
Views: 3626
Reputation: 31
I had the same issue. I had separate service to do the authentication where I had put the broadcastService subscription code. login-success was never fired. It turns out that, you have to subscribe the broadcastservice at the root component(app.component) only. Please check if you have subscribed it from multiple place.
if you need to put the subscription code in separate service other than app.component you can create the initialize() function with the subscription code inside the service and call it from app.component init(). That did the trick for me.
AuthenticationServicet.ts:
initialize() {
this._broadcastService.subscribe('msal:loginSuccess', (x) => {
console.log("login success.");
alert("success");
});
}
app.component.ts:
ngOnInit() {
this._authenticationService.initialize();
}
Upvotes: 3