Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle popup login errors #3290

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading