Skip to content

Commit

Permalink
fix: handle popup login errors (#3290)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnickii authored Sep 12, 2024
1 parent 0250086 commit 76a013d
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/providers/mgt-msal2-provider/src/Msal2Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
InteractionRequiredAuthError,
SsoSilentRequest,
EventMessage,
AuthenticationResult
AuthenticationResult,
BrowserAuthError
} from '@azure/msal-browser';
import { AuthenticationProviderOptions } from '@microsoft/microsoft-graph-client';

Expand Down Expand Up @@ -476,8 +477,24 @@ export class Msal2Provider extends IProvider {
domainHint: this._domainHint
};
if (this._loginType === LoginType.Popup) {
const response = await this._publicClientApplication.loginPopup(loginRequest);
this.handleResponse(response?.account);
try {
const response = await this._publicClientApplication.loginPopup(loginRequest);
this.handleResponse(response?.account);
} catch (error) {
switch (true) {
case error instanceof BrowserAuthError && error.errorCode === 'user_cancelled':
console.warn('🦒: User cancelled the login flow.');
this.setState(ProviderState.SignedOut);
break;
case error instanceof BrowserAuthError && error.errorCode === 'interaction_in_progress':
console.warn('🦒: Login already in progess. Close the popup to login again.');
this.setState(ProviderState.SignedOut);
break;
default:
console.error('🦒: Error occurred during login:', error);
throw error;
}
}
} else {
const loginRedirectRequest: RedirectRequest = { ...loginRequest };
await this._publicClientApplication.loginRedirect(loginRedirectRequest);
Expand Down

0 comments on commit 76a013d

Please sign in to comment.