[Due for payment 2026-11-28] [$175] Security - Valid magic code is not accepted when reopening an account
If you havenβt already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: 9.4.95-0 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/test-runs/76118653/folder/52723519/41236673/1807066502?sort=%2Bidentifier Email or phone of affected tester (no customers): n/a Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: iPhone 13 iOS 26.6 App Component: User Settings
Action Performed:
- Open the app
- Navigate to Account > Security > Close account
- Enter some text in the first input
- Enter the email in the second input and tap on "close account"
- Verify you are logged out
- Enter the email of the account you just closed
- Enter a valid magic code
Expected Result:
The user should be able to reopen the account and sign in successfully
Actual Result:
Nothing happens after entering a valid magic code. After tapping the Sign In button, the "Incorrect magic code" error appears.
Workaround:
Unknown
Platforms:
- [x] Android: App
- [ ] Android: mWeb Chrome
- [x] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [ ] Windows: Chrome
- [ ] MacOS: Chrome Safari
Screenshots/Videos
https://github.com/user-attachments/assets/af1c5436-44c0-4ed5-ac82-7bc619606e4b
Applause Internal Information Exported by: Julia Ponikarchuk Bug ID: 7272177
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022104893255610467459
- Upwork Job ID: 2104893255610467459
- Last Price Increase: 2026-09-29
- Automatic offers:
- TaduJR | Reviewer | 112959583
Issue Owner
Current Issue Owner: @mallenexpensify
While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/f9aaee604638e5f8e2ecb1c04ae6e032573ea069aa64a25a73cb098fc7d1296d
Proposal
What is the root cause of that problem?
Closing the account on the iOS/Android apps (HybridApp) wipes the local HybridApp sign-in flag. As a result, the next sign-in succeeds on the server, but the app never leaves the magic code screen.
closeAccountdoes not go through the normal sign-out path. It relies on the server clearing all Onyx data (User.ts:181-211). That clear removeshybridApp.useNewDotSignInPage. OnlyresetSignInFlow()sets this flag back totrue, and only the normal sign-out calls it (SignInRedirect.ts:115).- The magic code auto-submits.
SigninUsersucceeds, uses up the code, and returns anauthToken. signInToOldDotAndChooseExperiencereturns early becauseuseNewDotSignInPageis not set, soreadyToShowAuthScreensis never set totrue(HybridApp.ts:89).- On HybridApp, the signed-in screens only render when
readyToShowAuthScreensistrue(AppNavigator.native.tsx:17-22). The magic code form stays on screen, so "nothing happens." - Tapping Sign In sends the already-used code again. The server rejects it with "Incorrect magic code."
This explains why only the native apps are affected: on web, authenticated alone shows the signed-in screens.
What changes do you think we should make in order to solve the problem?
In closeAccount, after a successful response on HybridApp, reset the HybridApp sign-in flow alongside signOutFromOldDot(). For example, call resetSignInFlow() or send the user through redirectToSignIn(). The next sign-in then runs the normal HybridApp flow and shows the signed-in screens.
Make sure the reset runs after the server-driven Onyx clear. Otherwise the clear can wipe the flag again.
What alternative solutions did you explore? (Optional)
Give ONYXKEYS.HYBRID_APP a default of {useNewDotSignInPage: true} in the HybridApp Onyx initialKeyStates. Any Onyx.clear(), from close account or any other server-driven clear, then restores a usable sign-in state.
Confidence, unverified points, and related changes
Confidence: medium. The code path supports this explanation, but I have not confirmed it on a device or in production logs.
- I could not test on web: Melvin cannot get magic codes to re-sign in a closed account. Web is not a reported platform anyway.
- To confirm, check the tester's requests.
SigninUser#1 should succeed and #2 should fail with "Incorrect magic code." The client log should also lack[HybridApp] Performing sign-in on OldDot sideafter the firstSigninUser. - Possible workaround this predicts: force-quit and reopen the app after closing the account, then sign in.
- Other possible blockers on the same path: a reopened account's
SigninUserresponse may lacknvp_tryNewDot,autoGeneratedLogin/autoGeneratedPassword, or the 2FA fields thatHybridApp.ts:98requires. That would also leave the user stuck. It needs backend or log checks. - Recent change to this flow: [Payment due @suneox] Add validate code page for CloseAccount (merged 2026-09-19, included in 9.4.95-0). It moved
signOutFromOldDot()to run only after a successful response. I could not check whether the nativesignOutFromOldDot(in Mobile-Expensify) used to restore this flag, so I have not confirmed this PR as the regression. - I did not find likely duplicate open issues.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/102528) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @TaduJR (External)
Job added to Upwork: https://www.upwork.com/jobs/~022104893255610467459
Proposal
Please re-state the problem that we are trying to solve in this issue.
On HybridApp (iOS / Android), when reopening a previously closed account, entering a valid magic code does not advance the user past the magic code screen. Tapping "Sign In" again results in an "Incorrect magic code" error because the code was already consumed.
What is the root cause of that problem?
- In
src/libs/actions/User.tswithincloseAccount: When an account is closed, upon server response, the app only callsHybridAppModule.signOutFromOldDot(). It does not callresetSignInFlow(), nor does it route throughclearStorageAndRedirect(which is what normal sign-out does inSignInRedirect.ts:115). - When the backend processes
CloseAccount, a Pusher event clears all Onyx data. This wipesONYXKEYS.HYBRID_APP, resettinghybridApp.useNewDotSignInPagetoundefined. - When the user subsequently attempts to reopen the account and signs in with their magic code,
SigninUsersucceeds and consumes the magic code. - However, in
src/libs/HybridApp.tswithinsignInToOldDotAndChooseExperience:
Becauseif (!session?.authToken || !hybridApp?.useNewDotSignInPage) { return; }hybridApp?.useNewDotSignInPageis undefined/falsy, the function returns immediately. - Consequently,
setReadyToShowAuthScreens(true)is never called. - In
AppNavigator.native.tsx, authenticated screens only render whenreadyToShowAuthScreensistrue. The UI remains stuck on the magic code form. - Any subsequent tap on "Sign In" attempts to resubmit the already-used magic code, causing the server to return "Incorrect magic code".
What changes do you think we should make in order to solve the problem?
- In
src/libs/actions/User.ts(closeAccount): When the close account request succeeds on HybridApp, callresetSignInFlow()alongsideHybridAppModule.signOutFromOldDot():API.write(WRITE_COMMANDS.CLOSE_ACCOUNT, parameters, { optimisticData, failureData, }).then((response) => { if (!CONFIG.IS_HYBRID_APP || response?.jsonCode !== CONST.JSON_CODE.SUCCESS) { return; } resetSignInFlow(); HybridAppModule.signOutFromOldDot(); }); - Additionally, in
initialKeyStates.ts(or wherever initial Onyx key state is registered forONYXKEYS.HYBRID_APP), ensureuseNewDotSignInPage: trueis preserved as the default state so that any server-drivenOnyx.clear()leaves the client in a valid ready-to-sign-in state.
What alternative solutions did you explore? (Optional)
Calling redirectToSignIn('closeAccount') upon successful completion of closeAccount. However, calling resetSignInFlow() directly keeps the lightweight nature of the existing completion callback without redundant redirect transitions.
@TaduJR Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
@TaduJR Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
On HybridApp (iOS / Android), when reopening a previously closed account, entering a valid magic code does not transition the user past the magic code screen. Tapping "Sign In" a second time returns "Incorrect magic code" because the magic code was already consumed during the initial sign-in attempt. There are two interconnected root causes: When the reopened account subsequently signs in with a magic code: Call Add Unit Test ( Manual Regression Verification:Proposal
Please re-state the problem that we are trying to solve in this issue.
What is the root cause of that problem?
resetSignInFlow() in User.closeAccount:
During normal user login, src/libs/HybridApp.ts:119 sets setUseNewDotSignInPage(false).
When a user closes their account, src/libs/actions/User.ts:206-211 handles the successful CLOSE_ACCOUNT response by calling only HybridAppModule.signOutFromOldDot(). Unlike standard sign-out in src/libs/actions/SignInRedirect.ts:114-117, it never invokes resetSignInFlow().[ONYXKEYS.HYBRID_APP] in initialKeyStates:
When CloseAccount succeeds, the backend triggers a Pusher clear / server-driven Onyx clear. In src/setup/index.ts:55-70, ONYXKEYS.HYBRID_APP does not have default initial key states defined. Consequently, when Onyx is wiped or re-initialized, hybridApp.useNewDotSignInPage is cleared to undefined (or remains false if preserved).
SigninUser API call succeeds on the server and returns authToken.src/libs/HybridApp.ts:89-91, signInToOldDotAndChooseExperience checks:
Since if (!session?.authToken || !hybridApp?.useNewDotSignInPage) {
return;
}
hybridApp?.useNewDotSignInPage is false or undefined, the function returns early and never calls setReadyToShowAuthScreens(true).src/libs/Navigation/AppNavigator/AppNavigator.native.tsx:17-23, authenticated screens are guarded by:
Because return authenticated && hybridApp?.readyToShowAuthScreens;
readyToShowAuthScreens is false, the UI remains stuck on the magic code entry page.What changes do you think we should make in order to solve the problem?
resetSignInFlow() in User.closeAccount:
In src/libs/actions/User.ts:206-211, import resetSignInFlow from @userActions/HybridApp and invoke it upon successful completion:API.write(WRITE_COMMANDS.CLOSE_ACCOUNT, parameters, {
optimisticData,
failureData,
}).then((response) => {
// The account stays open when the validateCode is rejected, so OldDot must stay signed in to keep the state of both apps in sync
if (!CONFIG.IS_HYBRID_APP || response?.jsonCode !== CONST.JSON_CODE.SUCCESS) {
return;
}
resetSignInFlow();
HybridAppModule.signOutFromOldDot();
});
ONYXKEYS.HYBRID_APP to initialKeyStates in setup/index.ts:
In src/setup/index.ts:55-70, register default initial states so any Onyx.clear() (server-driven or local) automatically restores a clean sign-in state:[ONYXKEYS.HYBRID_APP]: {
readyToShowAuthScreens: false,
useNewDotSignInPage: true,
},
What alternative solutions did you explore? (Optional)
closeAccount completion through clearStorageAndRedirect('closeAccount'): While functional, clearStorageAndRedirect initiates additional full navigation tear-downs and telemetry that could conflict with the backend's server-driven data purge. Adding resetSignInFlow() alongside HybridAppModule.signOutFromOldDot() and setting the fallback in initialKeyStates provides a robust, defense-in-depth fix without side effects.Tests
tests/unit/CloseAccountTest.ts):
CONFIG.IS_HYBRID_APP = true.ONYXKEYS.HYBRID_APP with {useNewDotSignInPage: false, readyToShowAuthScreens: true}.closeAccount('test reason', '123456') simulating a CONST.JSON_CODE.SUCCESS response.ONYXKEYS.HYBRID_APP is updated with {useNewDotSignInPage: true, readyToShowAuthScreens: false}.Onyx.clear().ONYXKEYS.HYBRID_APP in initialKeyStates restores {useNewDotSignInPage: true, readyToShowAuthScreens: false}.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0170d6b02e9440e604
β Contributor details stored successfully. Thank you for contributing to Expensify!
@TaduJR Still overdue 6 days?! Let's take care of this!
@TaduJR Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!
@TaduJR 12 days overdue. Walking. Toward. The. Light...
@TaduJR 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!
This issue has not been updated in over 14 days. @TaduJR eroding to Weekly issue.
@TaduJR this issue is now 4 weeks old, please consider:
- Finding a contributor to fix the bug
- Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
- If you have any questions, don't hesitate to start a discussion in #expensify-open-source
Thanks!
@MelvinBot implement this
π€ Draft PR created: Restart the HybridApp sign-in flow after closing an account Please mark it as "Ready for review" or ask me to do that for you when it is ready for review.
The PR adds the HybridApp sign-in reset (useNewDotSignInPage: true, readyToShowAuthScreens: false) to the CloseAccount request's successData. Onyx applies it after the server's clear, so the next magic code sign-in shows the signed-in screens.
One difference from the proposal: I didn't put the reset in the .then callback. API.write resolves when the request is queued, before the response arrives. A reset there would be wiped by the clear.
β οΈ For the same reason, HybridAppModule.signOutFromOldDot() in that .then never runs. I left it unchanged and flagged it in the PR for a decision.
The new unit tests pass and fail without the fix. I haven't tested this on a device: the bug only affects iOS and Android, and closing the shared test account can't be undone.
Triggered auto assignment to @mollfpr, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
π£ @TaduJR π An offer has been automatically sent to your Upwork account for the Reviewer role π Thanks for contributing to the Expensify app!