'MSAL2.0 Login Redirect not getting account despite succesfull login with Azure. --Angular 13

I am using Angular 13 and @azure/msal-angular 2.1.1. I have set up the login using the redirect option. It works perfectly in Chrome, but when I try it on different browsers like firefox, the application doesn't get any account info after the login through the Microfost screen. I wonder if anyone has seen something like this. getAllAccounts and getActiveAccount always return null. This is what I have in my login page:

const accounts = this.authServiceMsal.instance.getAllAccounts();
    if (accounts.length > 0) {
        this.authServiceMsal.instance.setActiveAccount(accounts[0]);
    }

    this.authServiceMsal.instance.addEventCallback((event) => {
        // set active account after redirect
        if (event.eventType === EventType.LOGIN_SUCCESS && event.payload.account) {
            const azAccount = event.payload.account;
            this.authServiceMsal.instance.setActiveAccount(azAccount);
        }
    });

    // handle auth redired/do all initial setup for msal
    this.authServiceMsal.instance.handleRedirectPromise().then(authResult=>{
        // Check if user signed in
        const azAccount = this.authServiceMsal.instance.getActiveAccount();
        if(!azAccount){
            // redirect user to login page
            this.authServiceMsal.instance.loginRedirect();
        }
    }).catch(err=>{
        // TODO: Handle errors
        console.log(err);
    });

And the msal set up on the module side:

MsalModule.forRoot(new PublicClientApplication ({
        auth: {
            clientId: authentication.azureClintId,
            authority: authentication.azureTenantId,
            redirectUri: authentication.azureRedirectUri
        },
        cache: {
            cacheLocation: 'localStorage',
            storeAuthStateInCookie: isIE, 
        },
    }),
    {
        interactionType: InteractionType.Redirect,
        authRequest: {
            scopes: ['user.read']
        }
    },
    {
        interactionType: InteractionType.Redirect,
        protectedResourceMap: new Map<string, string[]>([
            [ authentication.azureGraphtUri, ['user.read']]
        ]),

    })

The redirect URI goes to localhost:4200

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source