we are moving to MSAL from Auth0 and previously we did authentication in APP_INITIALIZER and then added other async call after that.
return (): Promise<void> => {
return new Promise((resolve) => {
authService
.processAuthenticationData()
.then((res) => {
// actions$.pipe(ofType(loadPermisions) and so on
I want to keep this behaviour with MSAL but i am struggling to that.
Does anybody have any experiences with this approach or any tips or recommendations how to achieve it? Thanks
if (!msalService.instance.getActiveAccount()) {
console.log("no logged in");
msalService.loginRedirect();
}
return () =>
msalService.handleRedirectObservable().pipe(
takeWhile((response) => !!response),
tap((response) => {
console.log("logged", response);
if (response) {
msalService.instance.setActiveAccount(response.account);
}
}),
);
This doesn't work because 'instance' has to active user so it keeps redirecting, also i am not sure if redirect causes APP_INITIALIZED to cancel and then after redirecting back starts over?
return () =>
msalService.loginRedirect().pipe(
tap(() => console.log('after login redirect')),
concatMap(() =>
msalService.handleRedirectObservable().pipe(
tap((response) => {
console.log("login reaction ", response);
msalService.instance.setActiveAccount(response.account);
}),
),
),
);
This doesnt work probably because handleRedirectObservable is not subscribed it time of redirecting back from loginRedirect?
Plus there is also msalBroadcastService but i am not sure if its right way.