Skip to content

Commit 4dd36e7

Browse files
runway-github[bot]lwin-kyawgauthierpetetin
authored
release(runway): cherry-pick fix: fixed User Login Cancelled Error for firefox cp-13.9.0 (#37672)
- fix: fixed User Login Cancelled Error for firefox cp-13.9.0 (#37658) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/37658?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: #37645 ## **Manual testing steps** 1. In firefox, start new onboarding with social login. 2. Before completing the social login, close the window. 3. User should not see Login Error modal ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds cross-browser detection for user-cancelled OAuth logins and updates OAuth flow and onboarding UI to suppress errors when users close the login window, including Firefox-specific message support. > > - **Shared/Error Handling**: > - Add `OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR_FIREFOX` and new helper `isUserCancelledLoginError` to detect user-cancelled OAuth across browsers. > - **OAuth Service (`app/scripts/services/oauth/oauth-service.ts`)**: > - Replace `#isUserCancelledLoginError` with `#getUserCancelledLoginError` using `isUserCancelledLoginError` and return the original error when present. > - On missing `responseUrl`, check for user-cancelled error before throwing `NO_REDIRECT_URL_FOUND_ERROR`. > - **Onboarding UI (`ui/pages/onboarding-flow/welcome/welcome.js`)**: > - Use `isUserCancelledLoginError` to ignore user-cancelled cases in `handleSocialLoginError` and `handleLoginError`. > - Remove unnecessary logging; keep existing error-to-UI mapping unchanged otherwise. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 23ec974. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> [ec63edb](ec63edb) Co-authored-by: Lwin <147362763+lwin-kyaw@users.noreply.github.com> Co-authored-by: Gauthier Petetin <gauthierpetetin@hotmail.com>
1 parent ed9ed13 commit 4dd36e7

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

app/scripts/services/oauth/oauth-service.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { AuthConnection } from '@metamask/seedless-onboarding-controller';
22
import log from 'loglevel';
3-
import { OAuthErrorMessages } from '../../../../shared/modules/error';
3+
import {
4+
isUserCancelledLoginError,
5+
OAuthErrorMessages,
6+
} from '../../../../shared/modules/error';
47
import { checkForLastError } from '../../../../shared/modules/browser-runtime.utils';
58
import { TraceName, TraceOperation } from '../../../../shared/lib/trace';
69
import { BaseLoginHandler } from './base-login-handler';
@@ -204,12 +207,13 @@ export default class OAuthService {
204207
reject(error);
205208
}
206209
} else {
207-
if (this.#isUserCancelledLoginError()) {
208-
reject(
209-
new Error(OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR),
210-
);
210+
const userCancelledLoginError =
211+
this.#getUserCancelledLoginError();
212+
if (userCancelledLoginError) {
213+
reject(userCancelledLoginError);
211214
return;
212215
}
216+
// Throw default error for no redirect URL found
213217
reject(
214218
new Error(OAuthErrorMessages.NO_REDIRECT_URL_FOUND_ERROR),
215219
);
@@ -357,9 +361,12 @@ export default class OAuthService {
357361
return url.searchParams.get('code');
358362
}
359363

360-
#isUserCancelledLoginError(): boolean {
364+
#getUserCancelledLoginError(): Error | undefined {
361365
const error = checkForLastError();
362-
return error?.message === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR;
366+
if (isUserCancelledLoginError(error)) {
367+
return error;
368+
}
369+
return undefined;
363370
}
364371

365372
async setMarketingConsent(

shared/modules/error.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export enum OAuthErrorMessages {
3939
USER_CANCELLED_LOGIN_ERROR = 'The user did not approve access.',
4040
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
4141
// eslint-disable-next-line @typescript-eslint/naming-convention
42+
USER_CANCELLED_LOGIN_ERROR_FIREFOX = 'User cancelled or denied access.',
43+
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
44+
// eslint-disable-next-line @typescript-eslint/naming-convention
4245
NO_REDIRECT_URL_FOUND_ERROR = 'No redirect URL found',
4346
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
4447
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -47,3 +50,17 @@ export enum OAuthErrorMessages {
4750
// eslint-disable-next-line @typescript-eslint/naming-convention
4851
INVALID_OAUTH_STATE_ERROR = 'Invalid OAuth state',
4952
}
53+
54+
/**
55+
* Checks if the Web Authentication error is a user cancelled error.
56+
*
57+
* @param error - The error to check.
58+
* @returns True if the error is a user cancelled login error, false otherwise.
59+
*/
60+
export function isUserCancelledLoginError(error: Error | undefined): boolean {
61+
// NOTE: Firefox and chrome have different error messages for user cancelled the social login window.
62+
return (
63+
error?.message === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR ||
64+
error?.message === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR_FIREFOX
65+
);
66+
}

ui/pages/onboarding-flow/welcome/welcome.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import React, {
88
} from 'react';
99
import { useDispatch, useSelector } from 'react-redux';
1010
import { useNavigate } from 'react-router-dom-v5-compat';
11-
import log from 'loglevel';
1211
import { Box } from '../../../components/component-library';
1312
import {
1413
ONBOARDING_COMPLETION_ROUTE,
@@ -41,7 +40,10 @@ import {
4140
import { getIsSeedlessOnboardingFeatureEnabled } from '../../../../shared/modules/environment';
4241
import { getBrowserName } from '../../../../shared/modules/browser-runtime.utils';
4342
import { PLATFORM_FIREFOX } from '../../../../shared/constants/app';
44-
import { OAuthErrorMessages } from '../../../../shared/modules/error';
43+
import {
44+
isUserCancelledLoginError,
45+
OAuthErrorMessages,
46+
} from '../../../../shared/modules/error';
4547
import { TraceName, TraceOperation } from '../../../../shared/lib/trace';
4648
import {
4749
AlignItems,
@@ -214,7 +216,7 @@ export default function OnboardingWelcome() {
214216
error instanceof Error ? error.message : 'Unknown error';
215217

216218
// Map raw OAuth error messages to UI modal-friendly constants
217-
if (errorMessage === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR) {
219+
if (isUserCancelledLoginError(error)) {
218220
setLoginError(null);
219221
return;
220222
}
@@ -354,9 +356,7 @@ export default function OnboardingWelcome() {
354356
);
355357

356358
const handleLoginError = useCallback((error) => {
357-
log.error('handleLoginError::error', error);
358-
const errorMessage = error.message;
359-
if (errorMessage === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR) {
359+
if (isUserCancelledLoginError(error)) {
360360
setLoginError(null);
361361
} else {
362362
setLoginError(LOGIN_ERROR.GENERIC);

0 commit comments

Comments
 (0)