Hi @Daren Almonina
The document (aka.ms/msaljs/browser-errors) has made a detailed analysis of the problem and given corresponding solutions, you can check them:
Error Message: Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API.
This error is thrown when an interactive API (loginPopup
, loginRedirect
, acquireTokenPopup
, acquireTokenRedirect
) is invoked while another interactive API is still in progress. The login and acquireToken APIs are async so you will need to ensure that the resulting promises have resolved before invoking another one.
Using loginPopup
or acquireTokenPopup
Ensure that the promise returned from these APIs has resolved before invoking another one.
To resolve this you should ensure all interactive APIs have resolved before invoking another one:
const request = { scopes: ["openid", "profile"] };
await msalInstance.loginPopup();
await msalInstance.acquireTokenPopup(request);
Using loginRedirect
or acquireTokenRedirect
When using redirect APIs, handleRedirectPromise
must be invoked when returning from the redirect. This ensures that the token response from the server is properly handled and temporary cache entries are cleaned up. This error is thrown when handleRedirectPromise
has not had a chance to complete before the application invokes loginRedirect
or acquireTokenRedirect
.
To resolve, you should wait for handleRedirectPromise
to resolve before calling any interactive API:
await msalInstance.handleRedirectPromise();
const accounts = msalInstance.getAllAccounts();
if (accounts.length === 0) {
// No user signed in
msalInstance.loginRedirect();
}
Or alternatively:
msalInstance
.handleRedirectPromise()
.then((tokenResponse) => {
if (!tokenResponse) {
const accounts = msalInstance.getAllAccounts();
if (accounts.length === 0) {
// No user signed in
msalInstance.loginRedirect();
}
} else {
// Do something with the tokenResponse
}
})
.catch((err) => {
// Handle error
console.error(err);
});
Note: If you are calling loginRedirect
or acquireTokenRedirect
from a page that is not your redirectUri
you will need to ensure handleRedirectPromise
is called and awaited on both the redirectUri
page as well as the page that you initiated the redirect from. This is because the redirectUri
page will initiate a redirect back to the page that originally invoked loginRedirect
and that page will process the token response.
Besides, after clicking the logout button, ensure that any authentication-related state (such as tokens or user information) is properly cleared to prevent any lingering issues. Refer to this issue.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion