Skip to content

Implement logic to prevent onboarding flow when 2FA setup is required.#72218

Merged
mountiny merged 12 commits into
Expensify:mainfrom
software-mansion-labs:fix/onboarding-required-2fa
Oct 15, 2025
Merged

Implement logic to prevent onboarding flow when 2FA setup is required.#72218
mountiny merged 12 commits into
Expensify:mainfrom
software-mansion-labs:fix/onboarding-required-2fa

Conversation

@blazejkustra

@blazejkustra blazejkustra commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Explanation of Change

Initially the idea from @mountiny was:

  • Fix the Google sign in flow in NewDot to correct set the 2fa flag <- this should be handled on the backend
  • Update the navigation/modal logic in App to always show the 2FA modal over anything else

However, onboarding has once again become complicated, its logic is fragmented and difficult to follow. Ideally, we should look for opportunities to refactor and simplify this flow 😢

Showing the 2FA modal above everything else would make the implementation even more complex and is not the ideal solution. With input from @WojtekBoman, we discussed an alternative approach: preventing onboarding from being displayed until the user has properly configured their 2FA (and after it is configured then redirect users to onboarding).

Fixed Issues

$ #70803
PROPOSAL: N/A

Tests

  1. Sign in as a new user
  2. Use this command in the console:
Onyx.merge('account' , {
  hasAccessibleDomainPolicies: true, 
  isFromPublicDomain: false,
  needsTwoFactorAuthSetup: true
});
  1. Refresh the page
  2. Verify that 2fa is required page is displayed

Other than that, we need to test:

  • Onboarding flow holistically
  • Verify that deeplinking works as before
  • 2FA flow

Offline tests

N/A

QA Steps

Prerequisites + domain setup:

  • Domain Is fully verified (do it as adim of a domain in OldDot)
  • Require 2FA for domain members
  • No group restrictions in the default domain group.

Steps:

  • Go to expensify.com
  • Click the Sign in button in the top left
  • Sign up with Google on an account that is domain controlled
  • Get redirect to NewDot as you’re a new user
  • Verify that 2fa is required modal is displayed to the user

Other than that, we need to test:

  • Onboarding flow holistically
  • Verify that deeplinking works as before

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
    • MacOS: Desktop
  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop

@mountiny mountiny requested a review from fedirjh October 9, 2025 15:16
@blazejkustra blazejkustra marked this pull request as ready for review October 9, 2025 15:20
@blazejkustra blazejkustra requested a review from a team as a code owner October 9, 2025 15:20
@melvin-bot melvin-bot Bot requested a review from parasharrajat October 9, 2025 15:23
@melvin-bot

melvin-bot Bot commented Oct 9, 2025

Copy link
Copy Markdown

@parasharrajat 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 October 9, 2025 15:23
@github-actions

github-actions Bot commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Oct 9, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.54545% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/libs/actions/TwoFactorAuthActions.ts 0.00% 6 Missing ⚠️
src/libs/actions/Welcome/index.ts 62.50% 3 Missing ⚠️
src/hooks/useOnboardingFlow.ts 85.71% 0 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
src/libs/Navigation/AppNavigator/AuthScreens.tsx 55.00% <100.00%> (+0.37%) ⬆️
...on/AppNavigator/Navigators/RightModalNavigator.tsx 3.77% <ø> (ø)
src/hooks/useOnboardingFlow.ts 88.00% <85.71%> (-3.31%) ⬇️
src/libs/actions/Welcome/index.ts 48.93% <62.50%> (+0.66%) ⬆️
src/libs/actions/TwoFactorAuthActions.ts 0.00% <0.00%> (ø)

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

🧪🧪 Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! 🧪🧪
Built from App PR #72218.

Android 🤖 iOS 🍎
https://ad-hoc-expensify-cash.s3.amazonaws.com/android/72218/index.html https://ad-hoc-expensify-cash.s3.amazonaws.com/ios/72218/index.html
Android iOS
Desktop 💻 Web 🕸️
https://ad-hoc-expensify-cash.s3.amazonaws.com/desktop/72218/NewExpensify.dmg https://72218.pr-testing.expensify.com
Desktop Web

👀 View the workflow run that generated this build 👀

@fedirjh

fedirjh commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

@blazejkustra I have tested in dev and got this result, the 2FA is working as expected only after we refresh the page.

CleanShot.2025-10-09.at.17.41.02.mp4

Comment thread src/hooks/useOnboardingFlow.ts Outdated
@blazejkustra

Copy link
Copy Markdown
Contributor Author

@fedirjh Could you try again? I pushed some new changes

@blazejkustra

blazejkustra commented Oct 10, 2025

Copy link
Copy Markdown
Contributor Author

This is how it works with current changes:

QuickTime.movie.mov

@mountiny

Copy link
Copy Markdown
Contributor

@fedirjh can you please test again? thanks!

Comment thread src/hooks/useOnboardingFlow.ts Outdated
@jmusial

jmusial commented Oct 10, 2025

Copy link
Copy Markdown
Contributor
  • lint failing :(

@github-actions

Copy link
Copy Markdown
Contributor

LGTM :feelsgood:. Thank you for your hard work!

@fedirjh fedirjh 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.

Looks great overall! it works well on my end. I’ve shared some feedback and possible improvements in the review.

Comment thread src/libs/Navigation/AppNavigator/AuthScreens.tsx Outdated
Comment thread src/libs/Navigation/AppNavigator/AuthScreens.tsx
Comment on lines -621 to -634
listeners={{
...modalScreenListenersWithCancelSearch,
beforeRemove: () => {
modalScreenListenersWithCancelSearch.beforeRemove();

// When a 2FA RHP page is closed, if the 2FA require page is visible and the user has now enabled the 2FA, then remove the 2FA require page from the navigator.
const routeParams = navigation.getState()?.routes?.at(-1)?.params;
const screen = routeParams && 'screen' in routeParams ? routeParams.screen : '';
if (!shouldShowRequire2FAPage || !account?.requiresTwoFactorAuth || screen !== SCREENS.RIGHT_MODAL.TWO_FACTOR_AUTH) {
return;
}
setShouldShowRequire2FAPage(false);
},
}}

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.

@blazejkustra The 2FA setup modal is displayed under the onboarding modal: I think we should consider either removing it when the onboarding modal is open or displaying the onboarding only when the 2FA modal is closed.

Image

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.

This change could add quite a bit of complexity to the code 🤔 The onboarding logic currently depends on:
!!account?.needsTwoFactorAuthSetup && !account?.requiresTwoFactorAuth.

Right after 2FA is configured, the user is redirected to the “Two-factor authentication enabled” page. At that point, the above logic returns false, which triggers the onboarding screen.

It’s not ideal as is, but automatically closing the “Two-factor authentication enabled” page wouldn’t be great either, the user wouldn’t get clear feedback that 2FA setup was completed successfully.

Keeping the user on the “Two-factor authentication enabled” page could work, but we’d need to introduce an additional frontend-controlled state like twoFactorAuthSetupAcknowledged. That could easily become messy and prone to edge cases (e.g., page refreshes or similar scenarios).

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.

Meanwhile I'm trying other approaches to improve the logic!

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.

@fedirjh What do you think? update logic to show 2FA setup page based on progress

QuickTime.movie.2.mov

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.

@blazejkustra Looks good to me and works as expected :

CleanShot.2025-10-13.at.11.55.15.mp4

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.

cc @blazejkustra

CleanShot.2025-10-13.at.14.09.35.mp4
Screenshot 2025-10-13 at 2 09 06 PM Screenshot 2025-10-13 at 2 10 05 PM

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.

Seems like we need to resolve this one still

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.

@fedirjh It looks like it worked for you this time, right? The 2FA-required page was hidden after 2FA was configured

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 pushed a logic change, could you check again? 👀

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.

Perfect, this is working as expected 🚀.

CleanShot.2025-10-15.at.13.47.26.mp4

@parasharrajat

Copy link
Copy Markdown
Member

Please remove me from reviewer list.

@blazejkustra

Copy link
Copy Markdown
Contributor Author

Working on it now 👀

@fedirjh fedirjh 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.

Looks good to me.

@blazejkustra blazejkustra requested a review from mountiny October 15, 2025 13:03
@mountiny

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
    • 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
MacOS: Desktop

@mountiny mountiny 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.

Changes look good to me, I think @fedirjh has tested this one well so we can move forwards

const [onboardingInitialPath, onboardingInitialPathResult] = useOnyx(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, {canBeMissing: true});
const isOnboardingInitialPathLoading = isLoadingOnyxValue(onboardingInitialPathResult);
const [onboardingInitialPath, onboardingInitialPathMetadata] = useOnyx(ONYXKEYS.ONBOARDING_LAST_VISITED_PATH, {canBeMissing: true});
const [account, accountMetadata] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});

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.

Maybe room for improvement would be to only pick the properties with selector if we need only some of them

@mountiny mountiny merged commit fc41e57 into Expensify:main Oct 15, 2025
24 of 27 checks passed
@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.

@m-natarajan

Copy link
Copy Markdown

@blazejkustra @mountiny We can't use verified domain controlled account. Could this be verified internally?

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.2.32-0 🚀

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

@blazejkustra

Copy link
Copy Markdown
Contributor Author

@blazejkustra @mountiny We can't use verified domain controlled account. Could this be verified internally?

I think @fedirjh has already verified that, so for QA I suggest testing the overall onboarding process and the 2FA flow.

@IuliiaHerets

Copy link
Copy Markdown

@blazejkustra can you please share QA steps that you want us to check?

@mountiny

Copy link
Copy Markdown
Contributor

@IuliiaHerets I think the existing sign in process and 2FA setup should be fine

@mountiny

Copy link
Copy Markdown
Contributor

I have asked @fedirjh to do internalQA on these steps here in staging

@IuliiaHerets

Copy link
Copy Markdown

@mountiny thank you

@fedirjh

fedirjh commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

This works as expected in staging 🚀

cc @IuliiaHerets

CleanShot.2025-10-16.at.12.56.34.mp4

@IuliiaHerets

Copy link
Copy Markdown

@fedirjh @mountiny So we can check off it in the checklist, right?

@fedirjh

fedirjh commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

So we can check off it in the checklist, right?

@IuliiaHerets Yes, let's do it.

@m-natarajan

Copy link
Copy Markdown

Yes, let's do it.

@fedirjh Done, Thanks

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.2.32-6 🚀

platform result
🖥 desktop 🖥 success ✅
🕸 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.

9 participants