Reputation: 25
I am using "@azure/msal-browser": "^2.1.0", with my React SPA that is hosted on Azure app service. In my App.js I am using msalInstance.acquireTokenPopup(tokenRequest) to get a auth token, and this triggers a pop in the browser to prompt user to login if they are not. I need to check if browser is allowing popup if not, ask user to enable it first and reload the app. Would be a great help if anyone has a good solution.
Upvotes: 1
Views: 3245
Reputation: 1
Using redirect is arguably from ancient times, and there are many reasons to avoid it, what it you web page had an audio call going, and you need refresh the token, just redirect away and drop the call? Use window.open to test for popups and tell the user to enable them if need be.
var popUp = window.open('/pop.html', 'Popup Test', 'width=100, height=100, left=24, top=24, scrollbars, resizable');
if (popUp == null || typeof (popUp) == 'undefined') {
alert('Please disable your pop-up blocker and refresh the page.');
}
else {
popUp.focus();
popUp.close();
}
Upvotes: 0
Reputation: 1
If the token request is triggered by a user-generated event handler - onclick()
et al - it shouldn't make a difference that the browser is running a pop-up blocker.
Popups exist from really ancient times...
You could also use .acquireTokenRedirect()
instead of .acquireTokenPopup()
Upvotes: 0