Skip to content

[$250] Log in - "Verify your work email" is not displayed, unable to merge newAccount #89886

Closed

Description

@jponikarchuk

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: v9.3.68-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/folder/13176924/test-cases/41237586
Email or phone of affected tester (no customers): lattelover1412+070518@gmail.com
Issue reported by: Applause Internal Team
Bug source: Regression TC Execution
Device used: Chrome, android
App Component: Other

Action Performed:

Precondition:
Login to OD as a expensifail account A
Create a workspace
Add expensifail account B as a member

  1. Launch app
  2. User logged in with brand new account (gmail)
  3. When "What’s your work email?" modal display >> enter expensifail account B from the precondition
  4. Tap "Add Work Email" button

Expected Result:

Step 5: a "Verify your work email" modal displayed with a field to enter magic code should be displayed, the magic code received and user is able complete the onboarding flow

Actual Result:

A page show "Could not add work email" displayed instead "Verify your work email" modal displayed with a field to enter magic code

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Video.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022052300928016840812
  • Upwork Job ID: 2052300928016840812
  • Last Price Increase: 2026-05-14
Issue OwnerCurrent Issue Owner: @carlosmiceli

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 7, 2026
  2. MelvinBot commented on May 7, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    The backend AddWorkEmail command is returning a non-200 response when the submitted work email belongs to an existing account that is already a workspace member. On the client side, AddWorkEmail() defines failureData that unconditionally sets isMergingAccountBlocked: true on any backend failure. This causes BaseOnboardingWorkEmail to render the OnboardingMergingAccountBlockedView ("Couldn't add work email") instead of navigating to the magic code verification screen.

    The success path relies entirely on the server returning OnyxUpdates with shouldValidate: true on NVP_ONBOARDING -- the client successData only clears the loading state. So when the backend errors out for this scenario, shouldValidate is never set and the useEffect that would navigate to the verification screen never triggers.

    What changes do you think we should make in order to solve the problem?

    This is likely a backend issue in the AddWorkEmail command handler. The backend should return a successful response with shouldValidate: true for the case where the work email belongs to an existing account/workspace member, so the user gets the magic code verification flow instead of an error.

    If the backend fix is confirmed, no client-side changes are needed -- the existing client logic already correctly handles shouldValidate: true by navigating to the verification screen.

    If there's a legitimate backend reason to reject this case, the client-side failureData in AddWorkEmail() could be made more granular by checking the server error response and providing a more helpful error message instead of the generic "Couldn't add work email" block.

    What alternative solutions did you explore? (Optional)

    I investigated a potential client-side race condition: updateOnboardingValuesAndNavigation uses Onyx.set (full replacement) with shouldValidate: undefined, which could theoretically wipe server-set values. However, this function is only called on back-button press from the validation screen, not during the initial AddWorkEmail flow, so it's unlikely to be the primary cause of this bug.

    Investigation details

    Flow traced:

    1. User enters work email on BaseOnboardingWorkEmail and taps "Add Work Email"
    2. submitWorkEmail calls AddWorkEmail(email) which sends API.write('ADD_WORK_EMAIL', {workEmail})
    3. Success path: Server returns 200 with OnyxUpdates setting shouldValidate: true on NVP_ONBOARDING -> useEffect navigates to ONBOARDING_WORK_EMAIL_VALIDATION route -> user sees magic code screen
    4. Failure path: Server returns non-200 -> client failureData sets isMergingAccountBlocked: true -> BaseOnboardingWorkEmail renders OnboardingMergingAccountBlockedView -> user sees "Couldn't add work email"

    Key code locations:


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on May 7, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 7, 2026
  5. David-2002065 commented on May 7, 2026

    @David-2002065
    Contributor

    Proposal

    What is the root cause of that problem?

    I tracked the regression to the AddWorkEmail action in src/libs/actions/Session/index.ts. Its failureData unconditionally writes isMergingAccountBlocked: true to NVP_ONBOARDING for any API failure:

    https://github.com/Expensify/App/blob/main/src/libs/actions/Session/index.ts#L1481-L1496

    The "What's your work email?" screen then renders OnboardingMergingAccountBlockedView (whose title is "Couldn't add work email") whenever that flag is true:

    https://github.com/Expensify/App/blob/main/src/pages/OnboardingWorkEmail/BaseOnboardingWorkEmail.tsx#L162-L168

    When the user enters an existing workspace member's email, the backend returns a non-success jsonCode so the user can be sent through the magic-code merge flow. The backend response carries the shouldValidate: true onyxData update that should navigate the user to ROUTES.ONBOARDING_WORK_EMAIL_VALIDATION (the "Verify your work email" modal — see the navigation effect at https://github.com/Expensify/App/blob/main/src/pages/OnboardingWorkEmail/BaseOnboardingWorkEmail.tsx#L71-L99). But because our local failureData runs on every non-success response and force-sets isMergingAccountBlocked: true, the block view wins the JSX condition and hides the verification flow entirely.

    This was introduced by 67adc770546 — "show blocking screen for all failures of addWorkEmail" on July 4, 2025. Prior to that commit, the screen only blocked when onboardingErrorMessage === ONBOARDING_2FA_REQUIRED_ERROR_MESSAGE, leaving the verify-email merge path untouched.

    What changes do you think we should make in order to solve the problem?

    I'd switch AddWorkEmail to API.makeRequestWithSideEffects so we can inspect the backend response and only set isMergingAccountBlocked for genuinely non-recoverable errors (e.g. the 2FA case). For everything else we let the backend-driven onyxData (shouldValidate, error message, etc.) drive the UI, which restores the merge/verify path:

    -    const failureData: Array<OnyxUpdate<typeof ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM | typeof ONYXKEYS.NVP_ONBOARDING>> = [
    +    const failureData: Array<OnyxUpdate<typeof ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM>> = [
             {
                 onyxMethod: Onyx.METHOD.MERGE,
                 key: ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM,
                 value: {
                     isLoading: false,
                 },
             },
    -        {
    -            onyxMethod: Onyx.METHOD.MERGE,
    -            key: ONYXKEYS.NVP_ONBOARDING,
    -            value: {
    -                isMergingAccountBlocked: true,
    -            },
    -        },
         ];

    And replace the fire-and-forget API.write with a side-effect call that decides what to do based on the response (mirroring the pattern already used by MergeIntoAccountAndLogin at https://github.com/Expensify/App/blob/main/src/libs/actions/Session/index.ts#L1569-L1577):

    -    API.write(
    -        WRITE_COMMANDS.ADD_WORK_EMAIL,
    -        {workEmail},
    -        {optimisticData, successData, failureData},
    -    );
    +    // eslint-disable-next-line rulesdir/no-api-side-effects-method
    +    API.makeRequestWithSideEffects(
    +        SIDE_EFFECT_REQUEST_COMMANDS.ADD_WORK_EMAIL,
    +        {workEmail},
    +        {optimisticData, successData, failureData},
    +    ).then((response) => {
    +        if (response?.jsonCode === CONST.JSON_CODE.SUCCESS) {
    +            return;
    +        }
    +        // Only block for non-recoverable failures (e.g. 2FA-protected work account).
    +        // For "needs verification" responses the backend already sets shouldValidate: true
    +        // via its own onyxData, which routes the user to the verify-magic-code modal.
    +        if (response?.message === CONST.ERROR.ONBOARDING_2FA_REQUIRED_ERROR_MESSAGE) {
    +            Onyx.merge(ONYXKEYS.NVP_ONBOARDING, {isMergingAccountBlocked: true});
    +        }
    +    });

    Supporting changes:

    • Re-add ONBOARDING_2FA_REQUIRED_ERROR_MESSAGE (or whichever specific blocking-error sentinels the backend uses) to CONST.ERROR — it was deleted alongside the regression in the same commit.
    • Add ADD_WORK_EMAIL to SIDE_EFFECT_REQUEST_COMMANDS in src/libs/API/types.ts and wire it into WRITE_COMMANDS accordingly.
    • No template changes needed in BaseOnboardingWorkEmail.tsx: it already reads onboardingValues?.shouldValidate to navigate to the verification modal and onboardingValues?.isMergingAccountBlocked to swap in the block view, so once the flag is set correctly the UI handles itself.

    What alternative solutions did you explore?

    1. Pure revert of 67adc770546. Removes the regression, but loses the protection for the 2FA-required case the original commit was trying to handle. The side-effect approach above keeps both behaviors.
    2. Flipping the JSX precedence in BaseOnboardingWorkEmail.tsx so shouldValidate wins over isMergingAccountBlocked. Treats the symptom rather than the cause; isMergingAccountBlocked is also persisted to NVP and read by BaseOnboardingWorkEmailValidation.tsx#L100, so the wrong flag would still leak into the validation screen.
    3. Backend-only fix (have the API respond with jsonCode: 200 + shouldValidate: true for existing-member emails). Plausible but out of scope here, and it leaves the frontend's "every failure = blocked" bug in place for any other transient error (timeouts, 5xx, etc.).
  6. melvin-bot commented on May 7, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @truph01 (External)

  7. Abdukhamid000 commented on May 7, 2026

    @Abdukhamid000
    Contributor

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  8. changed the title [-]Log in - "Verify your work email" is not displayed, unable to merge newAccount[/-] [+][$250] Log in - "Verify your work email" is not displayed, unable to merge newAccount[/+] on May 7, 2026
  9. melvin-bot commented on May 7, 2026

    @melvin-bot
  10. KJ21-ENG commented on May 7, 2026

    @KJ21-ENG
    Contributor

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  11. aswin-s commented on May 7, 2026

    @aswin-s
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2026-05-07 08:26:33 UTC.

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When a brand-new user completes signup and reaches the onboarding "What's your work email?" modal, entering an expensifail email that is already a member of an existing workspace causes the UI to show "Could not add work email" (the OnboardingMergingAccountBlockedView) instead of the expected "Verify your work email" magic-code screen. The user cannot proceed with onboarding.

    What is the root cause of that problem?

    The bug is in the AddWorkEmail action in src/libs/actions/Session/index.ts (lines 1480–1495).

    The failureData for the ADD_WORK_EMAIL API call unconditionally sets isMergingAccountBlocked: true on ONYXKEYS.NVP_ONBOARDING:

    const failureData = [
        // ...
        {
            onyxMethod: Onyx.METHOD.MERGE,
            key: ONYXKEYS.NVP_ONBOARDING,
            value: {
                isMergingAccountBlocked: true,  // ← set on ANY failure
            },
        },
    ];

    When BaseOnboardingWorkEmail.tsx (line 162) sees onboardingValues?.isMergingAccountBlocked === true, it replaces the whole form with OnboardingMergingAccountBlockedView — the "Could not add work email" screen.

    The problem: not every ADD_WORK_EMAIL failure is a genuine merge-block. In the reproduction steps, the submitted email (account B) is already a workspace member, which causes the server to return an error — but this is not a permanent merge-block situation. The client blindly sets isMergingAccountBlocked: true anyway, showing the wrong screen.

    Compare with MergeIntoAccountAndLogin (line 1568), which uses makeRequestWithSideEffects and inspects the response code before setting isMergingAccountBlocked: it only sets the flag when the error is not an invalid-code error. AddWorkEmail has no such discrimination — it sets the flag on every failure path.

    Permalink:

    const failureData: Array<OnyxUpdate<typeof ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM | typeof ONYXKEYS.NVP_ONBOARDING>> = [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM,
    value: {
    isLoading: false,
    },
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.NVP_ONBOARDING,
    value: {
    isMergingAccountBlocked: true,
    },
    },
    ];

    What changes do you think we should make in order to solve the problem?

    Switch AddWorkEmail from API.write to API.makeRequestWithSideEffects so we can inspect the server response and only set isMergingAccountBlocked: true when the server explicitly indicates a merge-block condition. Remove isMergingAccountBlocked: true from failureData entirely — network/transient failures should not block the user.

    File: src/libs/actions/Session/index.ts
    Function: AddWorkEmail (line 1458)

    function AddWorkEmail(workEmail: string) {
        const optimisticData = [
            {
                onyxMethod: Onyx.METHOD.MERGE,
                key: ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM,
                value: { onboardingWorkEmail: workEmail, isLoading: true },
            },
        ];
    
        const successData = [
            {
                onyxMethod: Onyx.METHOD.MERGE,
                key: ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM,
                value: { isLoading: false },
            },
        ];
    
        const failureData = [
            {
                onyxMethod: Onyx.METHOD.MERGE,
                key: ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM,
                value: { isLoading: false },
            },
            // Removed: isMergingAccountBlocked: true — set conditionally below instead
        ];
    
        // eslint-disable-next-line rulesdir/no-api-side-effects-method
        API.makeRequestWithSideEffects(
            SIDE_EFFECT_REQUEST_COMMANDS.ADD_WORK_EMAIL,
            {workEmail},
            {optimisticData, successData, failureData},
        ).then((response) => {
            if (response?.jsonCode === CONST.JSON_CODE.EXP_ERROR) {
                // Only block the merge flow when the server explicitly returns a merge-block error
                Onyx.merge(ONYXKEYS.NVP_ONBOARDING, {isMergingAccountBlocked: true});
            }
            // On success or non-blocking errors, shouldValidate drives navigation via the existing useEffect
        });
    }

    This requires adding ADD_WORK_EMAIL to SIDE_EFFECT_REQUEST_COMMANDS if it isn't already there.

    Blast radius: Isolated to AddWorkEmail. The useEffect in BaseOnboardingWorkEmail already handles navigation via shouldValidate on success — that path is unchanged. The only behaviour change is that transient/non-merge-block failures no longer show the permanent blocked screen.

    What alternative solutions did you explore? (Optional)

    1. Keep API.write but remove isMergingAccountBlocked from failureData entirely — simpler, but means merge-block failures also don't show the blocked screen. Not safe since genuine merge-blocks need that UI.

    2. Add a separate error key (e.g. addWorkEmailError) to distinguish failure types without touching isMergingAccountBlocked — workable but adds Onyx complexity. The makeRequestWithSideEffects approach is cleaner and consistent with how MergeIntoAccountAndLogin already handles this.

  12. github-actions commented on May 7, 2026

    @github-actions
    Contributor

    ⚠️ @Abdukhamid000 Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  13. 13 remaining items

  14. melvin-bot commented on May 19, 2026

    @melvin-bot

    Triggered auto assignment to @carlosmiceli, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  15. carlosmiceli commented on May 19, 2026

    @carlosmiceli
    Contributor

    @truph01 what is the question?

  16. truph01 commented on May 20, 2026

    @truph01
    Contributor

    In this test case:

    Precondition:
    Login to OD as a expensifail account A
    Create a workspace
    Add expensifail account B as a member
    
    1. Launch app
    2. User logged in with brand new account (gmail)
    3. When "What’s your work email?" modal display >> enter expensifail account B from the precondition
    4. Tap "Add Work Email" button.
    

    In step 4. Tap "Add Work Email" button - AddWorkEmail API is triggered here. It throws error:

    [applausetester+hb+1901@applause.expensifail.com](mailto:applausetester+hb+1901@applause.expensifail.com) is a login for an Expensify account with Single Sign-On (SSO/SAML) enabled.
    
    requestID: 9fe27253ecbbd007-HKG
    

    @carlosmiceli Could you confirm whether it is expected?

  17. carlosmiceli commented on May 20, 2026

    @carlosmiceli
    Contributor

    Yes, the BE intentionally rejects work emails whose domain has SAML/SSO configured, because SSO accounts can't be merged via the magic-code verification flow.

  18. melvin-bot commented on May 21, 2026

    @melvin-bot

    @carlosmiceli @truph01 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

  19. truph01 commented on May 22, 2026

    @truph01
    Contributor

    Yes, the BE intentionally rejects work emails whose domain has SAML/SSO configured, because SSO accounts can't be merged via the magic-code verification flow.

    @carlosmiceli If so, i think we can close this one

  20. carlosmiceli commented on May 22, 2026

    @carlosmiceli
    Contributor

    @jponikarchuk that sounds right, can we close this or will it be reopened?

  21. melvin-bot commented on May 25, 2026

    @melvin-bot

    @carlosmiceli Whoops! This issue is 2 days overdue. Let's get this updated quick!

  22. Abdukhamid000 commented on May 26, 2026

    @Abdukhamid000
    Contributor

    @carlosmiceli @truph01 so root cause from BE ?

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions