'MSAL login not working in production for node.js , Javascript application

I have used Msal.js for login to microsoft account inorder to call microsoft graph api. On local everything is working fine but after deployment on production, login is happening but again a login popup is opening up , and my web application is not redirected to home page.

My redirect uri is : "http://localhost:8080/"

I am using node.js to create the localhost server.

My config.js file is -

const msalConfig = {
    auth: {
      clientId: 'cbd4ec69-c747-4592-ae78-7d8d680d0428',
      redirectUri: 'http://localhost:8080/'
    }
  };
  
  const msalRequest = {
    scopes: [
        'user.read',
      'Files.Read',
       'Files.Read.All',
        'Files.ReadWrite',
         'Files.ReadWrite.All'
    ]
  }

I need to deploy my application on prod, i have made the whole application and now only this thing is not working.



Solution 1:[1]

One of the workaround we can follow to resolve the above issue,

Make sure that the port you are using its been updated in server.js with your preferred port number in redirect uri.

We can follow the below given MS DOC and use the sample code.

The sample code will work like, When a user initially clicks the Sign In button, the signIn method invokes the loginPopup function to sign the user in. The loginPopup method prompts and validates the user's credentials by opening a pop-up window with the Microsoft identity platform endpoint. Msal.js starts the authorization code flow after a successful sign-in.

For complete setup please refer this MICROSOFT DOCUMENTATION|Sign in users and call the Microsoft Graph API from a JavaScript .

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 AjayKumarGhose-MT