Skip to content

Add Sign out escape hatch to required 2FA overlay - #100077

Merged
luacmartins merged 22 commits into
Expensify:mainfrom
neerajbachani:91985-require-2fa-overlay-sign-out
Sep 29, 2026
Merged

luacmartins merged 22 commits into
Expensify:mainfrom
neerajbachani:91985-require-2fa-overlay-sign-out

Conversation

@neerajbachani

@neerajbachani neerajbachani commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Add a horizontal Sign out + Enable 2FA button row on the blocking require-2FA overlay. Sign out uses the same confirm modal as Settings, then redirects to sign-in so users can switch accounts.

$ #91985

Explanation of Change

This follow-up to #94486 adds the Sign out escape hatch that was de-scoped from the original PR. When the full-screen require-2FA overlay is shown, users now see a horizontal row with Sign out (left) and Enable 2FA (right). Tapping Sign out opens the same confirmation modal used on the Settings page; confirming calls signOutAndRedirectToSignIn() so users who signed into the wrong account can switch without completing 2FA setup. Enable 2FA behavior is unchanged.

For copilot delegates, Leave account uses disconnect() instead of sign-out. GPS points when leaving during an active trip are read once via connectWithoutView (see below) to avoid subscribing to full GPS_DRAFT_DETAILS and re-rendering Settings on every location tick.

Onyx.connectWithoutView approval

useSignOut uses a one-shot readOnce() helper (connectWithoutView + immediate disconnect) to read GPS_DRAFT_DETAILS only after the user confirms leaving a delegated account during an active GPS trip. Points are needed inside an async post-modal callback, not during render, so useOnyx would either require a full-object subscription (re-renders Settings on every GPS point merge) or a gpsPoints selector (same problem). The connection is ephemeral: connect, read once, disconnect on user action only.

Slack discussion (@frontend-performance approval): Pending — will add permalink after posting in #frontend-performance; Onyx review requested in PR comment

Fixed Issues

$ #91985
PROPOSAL: #91985 (comment)

Tests

  1. Log in with an account on a domain that requires 2FA (before completing onboarding if applicable)
  2. Verify the require-2FA blocking overlay appears with Sign out and Enable 2FA buttons displayed side-by-side in one row
  3. Tap Sign out and verify the "Are you sure?" confirmation modal appears with the same copy as Settings > Sign out
  4. Tap Cancel on the confirmation modal and verify you remain on the require-2FA overlay
  5. Tap Sign out again, tap Sign out on the confirmation modal, and verify you are redirected to the sign-in page
  6. Log back in to the same require-2FA account and tap Enable 2FA; verify the 2FA setup RHP opens with Settings > Security in the background (unchanged from Required 2FA setup screen is unresponsive, blocking new-domain login and account merge #94486)
  7. Verify that no errors appear in the JS console

Offline tests

  1. While offline, log in to a require-2FA account and reach the blocking overlay
  2. Tap Sign out, confirm on the modal, and verify sign-out still completes and redirects to sign-in once the action is confirmed

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 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 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)
  • 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)
  • 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.
  • 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-09-08.at.11.47.11.PM.mov
Android: mWeb Chrome
WhatsApp.Video.2026-09-08.at.23.54.29.mp4
iOS: Native
Screen.Recording.2026-09-08.at.11.39.41.PM.mov
iOS: mWeb Safari
Screen.Recording.2026-09-08.at.11.52.06.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-08-11.at.12.33.03.AM.online-video-cutter.com.mp4

Add a horizontal Sign out + Enable 2FA button row on the blocking
require-2FA overlay. Sign out uses the same confirm modal as Settings,
then redirects to sign-in so users can switch accounts.

Fixes Expensify#91985
@neerajbachani
neerajbachani requested review from a team as code owners September 1, 2026 19:55
@melvin-bot
melvin-bot Bot requested review from JmillsExpensify and thelullabyy and removed request for a team September 1, 2026 19:55
@melvin-bot

melvin-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

@thelullabyy 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 removed the request for review from a team September 1, 2026 19:55
@codecov

codecov Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
...s/ReplaceShouldUseStagingServerWithActiveServer.ts 100.00% <100.00%> (ø)
src/libs/readOnceOnyxValue.ts 100.00% <100.00%> (ø)
...c/pages/settings/useInitialSettingsPageMenuData.ts 87.00% <33.33%> (+15.03%) ⬆️
src/components/GpsDraftDetailsRefSync.tsx 0.00% <0.00%> (ø)
src/hooks/useSignOut.ts 86.44% <86.44%> (ø)
...rc/pages/RequireTwoFactorAuthenticationOverlay.tsx 48.48% <18.51%> (-3.37%) ⬇️
... and 70 files with indirect coverage changes

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

Copy link
Copy Markdown

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: 230816db4a

ℹ️ 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".

Extract Settings sign-out flow (receipt save, offline/GPS warnings) into
InteractiveSignOut and wire the overlay to it so sign-out matches Settings.
Rename overlay handlers per STYLE.md (enableTwoFactorAuth, confirmSignOut).
@neerajbachani

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 58740e275a

ℹ️ 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 thread src/libs/actions/InteractiveSignOut.ts Resolved
When the require-2FA overlay already confirmed sign-out, do not show the
same generic offline warning again; still show GPS and receipt prompts.
Remove unused InteractiveSignOutParams export for knip.
JmillsExpensify
JmillsExpensify previously approved these changes Sep 1, 2026

@JmillsExpensify JmillsExpensify left a comment

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.

Big fan of this one. I've hit it myself and it's really rough to go through. Testing steps LGTM

@thelullabyy

Copy link
Copy Markdown
Contributor

@neerajbachani Please check pipelines

@neerajbachani

Copy link
Copy Markdown
Contributor Author

@thelullabyy CI was failing on unrelated checks (typecheck / validateSchemas) - not from this PR's changes. Merged latest main into the branch and CI is green now

@neerajbachani

Copy link
Copy Markdown
Contributor Author

Hey @thelullabyy

While QA’ing and recording the sign-out escape hatch on latest main, I hit a separate pre-existing issue that blocked full testing in one account state:

Issue: “Stay ahead of the deadline” (trialPaymentReminder) modal reopens immediately after tapping Close or 'Add a Payment card'

Repro:

  1. Sign in with an account on free trial, no payment card, with an owned paid workspace
  2. Trigger the require-2FA blocking overlay
  3. Trial payment reminder modal appears on top
  4. Tap Close → modal reopens in a loop

Note: This doesn’t appear related to this PR (no changes to trial reminder code). It looks like existing behavior in TrialPaymentReminderModalManager / useTrialPaymentReminder, and the 2FA overlay isn’t treated as a blocking modal for trial reminder eligibility.

Happy to file a separate issue (or follow-up PR) if helpful didn’t include a fix here to keep this PR scoped to the sign-out hatch.

Screen.Recording.2026-09-04.at.12.13.43.AM.mov

@thelullabyy

Copy link
Copy Markdown
Contributor

@neerajbachani Let's add all other platforms recordings, I see you attached only MacOS Chrome recording

@thelullabyy

Copy link
Copy Markdown
Contributor

@Expensify/design Could you please check this design - is it acceptable? I see that Enable 2 factors... button text is cut-off

image

@dannymcclain

Copy link
Copy Markdown
Contributor

Could you please check this design - is it acceptable? I see that Enable 2 factors... button text is cut-off

I don't think that's ok—feel pretty unacceptable to truncate an action button haha. I think we should change the body text to say Your company requires two-factor authentication (2FA). and then change the button label to Enable 2FA.

@shawnborton

Copy link
Copy Markdown
Contributor

Can we just shorten the button label to be "Enable" or "Enable 2FA"?

@dannymcclain

Copy link
Copy Markdown
Contributor

@shawnborton JINX!!!!

@shawnborton

Copy link
Copy Markdown
Contributor

JINX! Also, where is the Figma mock for this? I wonder if these buttons should just hug and not be fixed width anyways?

@dannymcclain

Copy link
Copy Markdown
Contributor

Also, where is the Figma mock for this? I wonder if these buttons should just hug and not be fixed width anyways?

I don't think there is one, but I think this layout is essentially based off of the layout in this Figma file. But I agree, they could just be centered and hug their contents if the labels were Sign out & Enable 2FA.

@dannymcclain

Copy link
Copy Markdown
Contributor

Basically this:
image

@neerajbachani

Copy link
Copy Markdown
Contributor Author

@thelullabyy Thanks for the video. I've changed the overlay's Sign out to use exactly the same flow as Settings: no confirm when you are online, and the confirm only when you are offline, have a GPS trip running, or have unsaved receipts. That removes the confirm modal that stayed on screen during online sign-out.

If you test offline on local web, note that the dev proxy (web/proxy.ts) never answers when the upstream request fails. LogOut stays pending until the connection returns, then the redirect happens. On staging/production, or with USE_WEB_PROXY=false, the request fails right away and you land on the login page. Settings works the same way. No backend change is needed.

tgolen
tgolen previously approved these changes Sep 28, 2026
@thelullabyy

thelullabyy commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

I think we should fix the duplicated modal issue here instead of removing that modal @neerajbachani

Please revert the changes

Besides, even if we remove the modal, it is still missing loading indicator

Screen.Recording.2026-09-29.at.01.04.11.mov

@luacmartins
luacmartins removed their request for review September 28, 2026 17:37
@neerajbachani

neerajbachani commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@thelullabyy We didn't remove the confirm modal, it still shows. The overlay's Sign out now follows the same rules as Settings > Sign out on main:

  • Online, no GPS trip, no unsaved receipts: sign out right away, no modal (Settings on main). You can check this with any normal account: Settings > Sign out has no confirm.
  • Offline, a GPS trip running, or unsaved receipts: the confirm shows, same as Settings (hook).

Both screens call the same useSignOut().signOut(), so they can't drift apart.

You're right about the loading indicator. The button had isLoading, but the spinner stopped almost immediately because sign-out didn't wait for the LogOut request. I've fixed that: the button now keeps its spinner until you land on the login page, and a second press is ignored while it's in flight. That also fixes the duplicated modal when the confirm does show (offline, GPS, or receipts).

If you'd still prefer the overlay to always show a confirmation, I can add that back. From a product perspective, though, I don't think an additional confirmation is necessary on the first screen since the user has explicitly chosen to sign out. This is also consistent with the existing Settings > Sign out behavior. The duplicate-modal issue is covered either way now, since the button remains in the loading state until sign-out finishes.

Screen.Recording.2026-09-28.at.11.15.49.PM.mov

@github-actions

Copy link
Copy Markdown
Contributor

This PR adds a new Onyx.connectWithoutView call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @luacmartins, @chuckdries) — a review from any one of them is enough. Please add a link in your PR description to the Slack discussion where the @frontend-performance team approved using connectWithoutView here.

@mountiny
mountiny removed their request for review September 29, 2026 16:48
@mountiny

Copy link
Copy Markdown
Contributor

You can go ahead and merge @luacmartins

@Expensify Expensify deleted a comment from thelullabyy Sep 29, 2026
@luacmartins

luacmartins commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

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
  • 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 proper code patterns were followed (see Reviewing the code)
    • 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 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)
  • 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)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • 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
    • 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 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.
  • 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

@luacmartins
luacmartins merged commit 0be8e62 into Expensify:main Sep 29, 2026
35 of 42 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@OSBotify

Copy link
Copy Markdown
Contributor

✋ 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

🚀 Deployed to staging by https://github.com/luacmartins in version: 9.4.96-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed: no article in docs/articles describes the require-2FA screen or names its old Enable two-factor authentication button, and the new Sign out / Leave account button is an escape hatch for the edge case of signing into the wrong account, not a new workflow.


view run

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #102609 was identified to be related to this PR.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 9.4.99-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. No article under docs/articles describes the required-2FA screen or its old Enable two-factor authentication button. The new Sign out / Leave account button is an edge-case way out of that screen, for users who signed in to the wrong account.

What I checked
  • Two-Factor-Authentication.md says only that "Domain Admins can require all members on a domain to enable Two-Factor Authentication." That is still accurate. Its setup steps start from Account > Security, not from the blocking screen.
  • Join-your-company's-workspace.md (Step 5) and Login-Troubleshooting.md also start from Settings. Neither names the screen or its buttons.
  • The other changes (a shared useSignOut hook, the "(2FA)" added to the screen's subtitle, and the copilot leave flow) are internal or in-app copy that explains itself.

view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.99-2 🚀

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

Bundle Size Analysis (Sentry):

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.