Skip to content

[ECUK In-App 3DS] Prevent unwanted validate code resend and display rate limit errors in MFA flow#86320

Merged
chuckdries merged 12 commits intoExpensify:mainfrom
software-mansion-labs:dariusz-biela/fix/3ds/send-validate-code-bugs
Apr 1, 2026
Merged

[ECUK In-App 3DS] Prevent unwanted validate code resend and display rate limit errors in MFA flow#86320
chuckdries merged 12 commits intoExpensify:mainfrom
software-mansion-labs:dariusz-biela/fix/3ds/send-validate-code-bugs

Conversation

@dariusz-biela
Copy link
Copy Markdown
Contributor

@dariusz-biela dariusz-biela commented Mar 25, 2026

Explanation of Change

  1. Unwanted validate code resend on typing: onCodeInput dispatched SET_VALIDATE_CODE(undefined) which re-triggered process() via useEffect. Since process() saw no validateCode, it called requestValidateCodeAction() — sending a new email the user didn't request. Fixed by removing SET_VALIDATE_CODE(undefined) and keeping only CLEAR_CONTINUABLE_ERROR, which is not in the process() useEffect deps.

  2. Rate limit errors not displayed: Backend errors from VALIDATE_ACTION_CODE.errorFields.actionVerified (e.g. rate limit) were not shown to the user. Added inline error display on ValidateCodePage via FormHelpMessage. Error state is applied through failureData in Onyx, which SequentialQueue reliably handles — including infrastructure-level HTTP 429 errors.

  3. Unified resend to use requestValidateCodeAction: The resend button previously used the session-based resendValidateCode(contactMethod) which hits a different endpoint (RequestNewValidateCode). Unified to use requestValidateCodeAction (ResendValidateCode) — the same endpoint used for the initial send in Main.tsx.

Fixed Issues

$ #86285
PROPOSAL:

Tests

  1. Start MFA flow that requires validate code (registration path)
  2. Enter an invalid validate code and verify the error appears under the input
  3. Start typing a new code — verify no new email arrives in your inbox
  4. Submit a correct code — verify flow continues normally
  5. Trigger rate limit by repeatedly opening and closing the MFA flow without entering the magic code — verify the backend error message appears inline on the validate code page
  6. Press the resend button under normal conditions — verify a new code is sent and countdown resets
  • Verify that no errors appear in the JS console

Offline tests

  • N/A

Note: The dev menu (/test-tools) interferes with the MFA navigation stack when testing offline mode. Using browser DevTools to simulate offline works correctly. This is a pre-existing issue unrelated to this PR.

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-03-25.at.15.32.29.mp4
iOS: Native
Screen.Recording.2026-03-25.at.15.19.59.mp4
MacOS: Chrome / Safari
Screen.Recording.2026-03-25.at.15.11.25.mp4

Remove SET_VALIDATE_CODE(undefined) dispatch from onCodeInput so that
typing after an invalid code no longer re-triggers process() and sends
an unwanted email. Resend now only happens on explicit button press.

Switch requestValidateCodeAction to makeRequestWithSideEffects so
Main.tsx can detect send failures (e.g. rate limit) and log them.
Display backend errors from VALIDATE_ACTION_CODE.errorFields on
ValidateCodePage via FormHelpMessage. Unify resend button to use
requestValidateCodeAction instead of the session-based resendValidateCode.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...ges/MultifactorAuthentication/ValidateCodePage.tsx 0.00% <0.00%> (ø)
... and 16 files with indirect coverage changes

Copy link
Copy Markdown
Contributor

@JakubKorytko JakubKorytko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small comments, otherwise LGTM.

Avoid awaiting requestValidateCodeAction() before navigating to the
magic code page. The response is only used for breadcrumb logging,
while actual error display relies on Onyx failureData. This removes
the unnecessary delay before navigation.
@dariusz-biela dariusz-biela marked this pull request as ready for review March 25, 2026 15:05
@dariusz-biela dariusz-biela requested review from a team as code owners March 25, 2026 15:05
@melvin-bot melvin-bot bot requested a review from aimane-chnaif March 25, 2026 15:05
@melvin-bot
Copy link
Copy Markdown

melvin-bot bot commented Mar 25, 2026

@aimane-chnaif Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot requested review from JmillsExpensify and removed request for a team March 25, 2026 15:05
];

API.write(WRITE_COMMANDS.RESEND_VALIDATE_CODE, null, {optimisticData, successData, failureData});
// eslint-disable-next-line rulesdir/no-api-side-effects-method
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment why we need api response callback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, we need to note that we're only using makeRequestWithSideEffects so we can know the outcome for logging purposes

@MelvinBot
Copy link
Copy Markdown
Contributor

🔍 PR Review

Overall this is a well-structured fix that addresses three real problems. The approach is sound and the changes are minimal/focused. A few observations:

Looks Good

  1. Unwanted resend fix (core bug): Removing SET_VALIDATE_CODE(undefined) from onCodeInput is the correct fix. The old code was triggering process() on every keystroke (since state.validateCode is in the useEffect deps), which re-requested validate codes. CLEAR_CONTINUABLE_ERROR correctly avoids this since continuableError is not in the process() useEffect deps.

  2. makeRequestWithSideEffects migration: Switching from API.write to API.makeRequestWithSideEffects is appropriate for surfacing rate limit errors. The optimistic/success/failure data pattern is properly implemented with the actionVerified error field.

  3. Unified resend endpoint: Using requestValidateCodeAction (hits ResendValidateCode) instead of resendValidateCode (hits RequestNewValidateCode via Session) makes sense — the MFA flow should use the same endpoint consistently.

  4. Error display: The new FormHelpMessage for validateCodeActionError is properly placed after the other error messages.

Minor Observations

  1. Same-code resubmission edge case: With SET_VALIDATE_CODE(undefined) removed from onCodeInput, if a user submits an invalid code, gets the continuable error, then re-submits the exact same code, SET_VALIDATE_CODE("sameCode") won't change state.validateCode → the useEffect won't re-fire → nothing happens. This is unlikely in practice (users would get a new code or type a different one), but worth being aware of. The user can always press "Resend" as a workaround.

  2. WRITE_COMMANDS.RESEND_VALIDATE_CODE still exists: The command is now in both WRITE_COMMANDS and SIDE_EFFECT_REQUEST_COMMANDS. This is fine since Delegate.ts and SequentialQueue.ts still reference the write command variant. Just noting this is intentional.

  3. Unhandled promise in resendValidationCode: requestValidateCodeAction() is called without .then()/.catch() in the resend handler (unlike in Main.tsx where the .then() logs failures). The Onyx failure data handles the UI error display, so this isn't a bug — but a caught promise would be more defensive. Very minor.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 732b15c675

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +129 to 132
// Clear continuable error when user starts typing after an error
if (continuableError) {
dispatch({type: 'SET_VALIDATE_CODE', payload: undefined});
dispatch({type: 'CLEAR_CONTINUABLE_ERROR'});
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset validateCode when user starts correcting an invalid code

After an INVALID_VALIDATE_CODE continuable error, this handler now clears only continuableError and leaves state.validateCode unchanged. The MFA engine in Context/Main.tsx re-runs on state.validateCode changes, so if the user retries with the same code value (a common retry path after transient failures), SET_VALIDATE_CODE writes the same value and process() is not triggered, making Verify appear to do nothing. This is a regression from the previous behavior where the stored validate code was cleared before retry.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds plausible, but probably not a big deal?

Copy link
Copy Markdown
Contributor

@chuckdries chuckdries left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just need to add a comment then I think we're golden, it works like a charm

macOs chrome
MFA.validatecode.handling.fixed.mp4

];

API.write(WRITE_COMMANDS.RESEND_VALIDATE_CODE, null, {optimisticData, successData, failureData});
// eslint-disable-next-line rulesdir/no-api-side-effects-method
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, we need to note that we're only using makeRequestWithSideEffects so we can know the outcome for logging purposes

@aimane-chnaif
Copy link
Copy Markdown
Contributor

aimane-chnaif commented Mar 25, 2026

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
before.fix.mov
demo.mov

@rafecolton rafecolton self-requested a review March 25, 2026 16:52
@aimane-chnaif
Copy link
Copy Markdown
Contributor

Bug: 2 RBRs appear. Please follow the same pattern in other pages. i.e. contact methods

Screenshot 2026-03-25 at 5 21 51 pm Screenshot 2026-03-25 at 5 23 11 pm

@aimane-chnaif
Copy link
Copy Markdown
Contributor

@MelvinBot please suggest code changes based on this feedback

@MelvinBot
Copy link
Copy Markdown
Contributor

Based on the feedback about 2 RBRs appearing simultaneously, here are the suggested code changes:

Problem: Lines 242-244 render three independent FormHelpMessage components. When multiple error states are true at the same time (e.g., both hasAccountError and hasValidateCodeActionError), multiple red error messages appear stacked. The contact methods pages (e.g., BaseValidateCodeForm.tsx) avoid this by using error priority logic so only one message renders.

Fix 1 — Use a single FormHelpMessage with priority (lines 242-244):

Replace:

{hasContinuableError && <FormHelpMessage message={translate('validateCodeForm.error.incorrectMagicCode')} />}
{hasAccountError && <FormHelpMessage message={getLatestErrorMessage(account)} />}
{hasValidateCodeActionError && <FormHelpMessage message={Object.values(validateCodeActionError).at(0)} />}

With:

{(hasContinuableError || hasAccountError || hasValidateCodeActionError) && (
    <FormHelpMessage
        message={
            hasContinuableError
                ? translate('validateCodeForm.error.incorrectMagicCode')
                : hasAccountError
                    ? getLatestErrorMessage(account)
                    : Object.values(validateCodeActionError).at(0)
        }
    />
)}

This ensures only one FormHelpMessage renders at a time, with priority: continuable error > account error > validate action error. This matches the pattern in BaseValidateCodeForm.tsx where a single finalValidateError is selected via priority logic before display.

Fix 2 — Clear validateCodeActionError in onCodeInput (lines 119-133):

Per JakubKorytko's review comment, the onCodeInput handler clears account.errors and continuableError but not validateCodeActionError. A rate-limit error would persist while the user types. Add a clear call:

const onCodeInput = (text: string) => {
    setFormError({});
    setCanShowError(false);
    setInputCode(text);

    // Clear backend errors
    if (account?.errors) {
        clearAccountMessages();
    }

    // Clear validate code action errors (e.g. rate limit)
    if (hasValidateCodeActionError) {
        clearValidateCodeActionError('actionVerified');
    }

    // Clear continuable error when user starts typing after an error
    if (continuableError) {
        dispatch({type: 'CLEAR_CONTINUABLE_ERROR'});
    }
};

Fix 3 — Also update hasError derived state (line 65):

Since hasValidateCodeActionError is now a displayed error type, include it in the combined hasError flag so MagicCodeInput's hasError prop and the resend button logic account for it:

const hasError = hasAccountError || hasContinuableError || hasValidateCodeActionError;

These three changes together ensure: (a) only one error message displays at a time, (b) all error types clear on user input, and (c) the input field's error styling reflects all error sources.

@dariusz-biela
Copy link
Copy Markdown
Contributor Author

Fix 2 — Clear validateCodeActionError in onCodeInput (lines 119-133):

Per JakubKorytko's #86320 (comment), the onCodeInput handler clears account.errors and continuableError but not validateCodeActionError. A rate-limit error would persist while the user types. Add a clear call:

const onCodeInput = (text: string) => {
    setFormError({});
    setCanShowError(false);
    setInputCode(text);

    // Clear backend errors
    if (account?.errors) {
        clearAccountMessages();
    }

    // Clear validate code action errors (e.g. rate limit)
    if (hasValidateCodeActionError) {
        clearValidateCodeActionError('actionVerified');
    }

    // Clear continuable error when user starts typing after an error
    if (continuableError) {
        dispatch({type: 'CLEAR_CONTINUABLE_ERROR'});
    }
};

We intentionally don't clear validateCodeActionError in onCodeInput. This error comes from the backend rate limit on sending validate codes — typing a new code doesn't change the fact that we're still rate-limited. We only clear it when the user presses the resend button, which is the action that actually retries the request and may succeed after the rate limit window expires.

Replace multiple FormHelpMessage components with a single
OfflineWithFeedback wrapper around the Verify button. Errors now
display directly above the submit button with priority:
rate limit > invalid code > account error. This matches the
pattern used in BaseValidateCodeForm and prevents duplicate
error messages from appearing simultaneously.
validateCodeActionError is guaranteed non-empty when
hasValidateCodeActionError is true, making ?? {} dead code.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3270a122ad

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 145 to 147
if (continuableError) {
dispatch({type: 'SET_VALIDATE_CODE', payload: undefined});
dispatch({type: 'CLEAR_CONTINUABLE_ERROR'});
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reset stored validate code when retrying after code errors

When the user starts typing after an INVALID_VALIDATE_CODE, this block only clears continuableError but leaves state.validateCode unchanged. The MFA engine effect in Context/Main.tsx is keyed on state.validateCode (not continuableError), so if the user retries with the same code value, SET_VALIDATE_CODE does not change the dependency and process() will not run again. In practice, the Verify action can appear to do nothing until the input differs from the previous submitted code.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the user enters a valid code, they are immediately redirected; if they enter the same code again, we don't want them to have to confirm twice that it's invalid.

@aimane-chnaif
Copy link
Copy Markdown
Contributor

Larger padding above button

Screenshot 2026-03-26 at 1 54 44 pm

Expected:

Screenshot 2026-03-26 at 1 55 12 pm

@aimane-chnaif
Copy link
Copy Markdown
Contributor

Offline pattern is different from other magic code page. Is it expected?

Screenshot 2026-03-26 at 1 58 38 pm

Contact methods page:

Screenshot 2026-03-26 at 2 01 18 pm

@aimane-chnaif
Copy link
Copy Markdown
Contributor

Offline behavior is quite buggy. Please follow repro steps in this video:

Screen.Recording.2026-03-26.at.2.00.29.pm.mov
Screen.Recording.2026-03-26.at.1.59.30.pm.mov

@dariusz-biela
Copy link
Copy Markdown
Contributor Author

@aimane-chnaif

I spent some time figuring out why the offline mode isn't working properly for you, and it turns out it's because of our dev menu, which is messing up the navigation stack for MFA.

If you use DevTools to enter offline mode, everything works as expected.

I don't plan to fix this in this PR, as it's outside its scope. But it might be worth creating a separate issue for https://dev.new.expensify.com:8082/test-tools

Screen.Recording.2026-03-27.at.15.04.05.mp4

Replace p5 with ph5+pb5+mt4 on the Verify button so the gap between
the error message and the button matches BaseValidateCodeForm (16px
via mt4). Remove mb2 from errorRowStyles to avoid double spacing.
@dariusz-biela
Copy link
Copy Markdown
Contributor Author

@aimane-chnaif
I fixed the spacing.
image

Comment on lines +271 to +275
<OfflineWithFeedback
shouldDisplayErrorAbove
errors={errorMessage ? {error: errorMessage} : undefined}
errorRowStyles={[styles.mh5]}
style={[styles.w100, styles.mtAuto]}
Copy link
Copy Markdown
Contributor

@aimane-chnaif aimane-chnaif Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decided to use full page offline pattern, is OfflineWithFeedback needed for this button?
Or is it just for showing error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you're right. I added it at the very beginning to keep the styling the same as on the page you sent me, since it uses that component.

But it's definitely too heavy, so I'm switching to the lightweight FormHelpMessage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed the changes

OfflineWithFeedback is redundant since the page already uses
FullPageOfflineBlockingView. Use FormHelpMessage which provides
built-in accessibility (alert role, live region) and is designed
for displaying form validation errors.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7fe4188c0c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

API.write(WRITE_COMMANDS.RESEND_VALIDATE_CODE, null, {optimisticData, successData, failureData});
// We are using makeRequestWithSideEffects instead of API.write so that the caller can inspect the response and log failures
// eslint-disable-next-line rulesdir/no-api-side-effects-method
return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.RESEND_VALIDATE_CODE, null, {optimisticData, successData, failureData});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep throttled resend failures from bypassing failureData

Switching requestValidateCodeAction from API.write to API.makeRequestWithSideEffects changes failure semantics for ResendValidateCode: HTTP/network failures (including 429 throttling) reject the promise before SaveResponseInOnyx can apply failureData, so VALIDATE_ACTION_CODE.errorFields.actionVerified and isLoading are never updated. The previous write path handled this command in SequentialQueue and explicitly applied failure data on throttling; after this change, callers like MFA only attach .then(...), so throttled resend attempts can result in no inline error state and a rejected promise instead of the expected rate-limit feedback.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, wouldn't that mean that this PR doesn't work at all thought? 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Experimentally, this MFA magic code input correctly handles when ResendValidateCode throttles. I guess we should double check other places that might call it though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it right away

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I checked, and the situation isn't as black and white as the Codex makes it out to be.

The implementation using makeRequestWithSideEffects handles 99% of errors, which is why it works in this PR.

The only errors it doesn’t handle are infrastructure errors that actually come in the form of an HTTP status; all others that we send via JSON from the backend work.

However, I’ll actually revert this change because it isn’t really necessary in the context of the entire PR. And it might cause problems in that 1%.

@JmillsExpensify JmillsExpensify requested review from joekaufmanexpensify and removed request for JmillsExpensify March 29, 2026 21:21
…t remnants

API.write ensures failureData is reliably applied via SequentialQueue,
including on infrastructure-level HTTP 429 errors. Remove RESEND_VALIDATE_CODE
from SIDE_EFFECT_REQUEST_COMMANDS and clean up .then() chains in callers.
Copy link
Copy Markdown
Contributor

@joekaufmanexpensify joekaufmanexpensify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change makes sense from a product perspective

@dariusz-biela
Copy link
Copy Markdown
Contributor Author

@aimane-chnaif
Do you have any other comments on this PR?

@chuckdries
Copy link
Copy Markdown
Contributor

@dariusz-biela Just a small nit - can you update the QA steps to not involve checking network/logs? Should be fine to just verify that no new email arrives in the tester's inbox

@chuckdries chuckdries merged commit bb938fc into Expensify:main Apr 1, 2026
36 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

🚧 @chuckdries has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented Apr 1, 2026

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented Apr 2, 2026

🚀 Deployed to staging by https://github.com/chuckdries in version: 9.3.52-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@MelvinBot
Copy link
Copy Markdown
Contributor

No help site changes are required for this PR.

The changes here are internal bug fixes to the MFA validate code page — fixing unwanted code resend on typing, displaying rate limit errors inline, and unifying the resend action. These don't alter any user-facing steps, feature names, navigation paths, or button labels documented in the help site.

I reviewed the relevant articles:

  • docs/articles/new-expensify/settings/Two-Factor-Authentication.md
  • docs/articles/expensify-classic/settings/Two-Factor-Authentication.md

Both describe the 2FA setup and login flow at a level that isn't affected by these code-level fixes.

@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented Apr 7, 2026

🚀 Deployed to production by https://github.com/roryabraham in version: 9.3.52-9 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants