Skip to content

[$250] Login - Unable to login to app once logout & attempt to login back #84849

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: 9.3.35-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/TR-8318/folder/13176924/41237549/1241615098
Email or phone of affected tester (no customers): kiatest.80+ck31026@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Critical User Impact
Device used: iPhone 16/iOS 18.7.1
App Component: Other

Action Performed:

  1. Launch Hybrid app
  2. Create a new gmail account (Note: OR try to login with any existing account)
  3. Go through the onbaording
  4. Logout of app
  5. Enter same email address & valid magic code

Expected Result:

User able to login back to app once he logout & attempt to login back

Actual Result:

Unable to login to app once logout & login back. After entering magic code, loading icon seen on Sign in button & revert to Sign in & user is not signed in

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7098479_1773111576663.expensifial_account.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @grgia
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022043616406257032348
  • Upwork Job ID: 2043616406257032348
  • Last Price Increase: 2026-04-13

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    and removed on Apr 13, 2026
  2. MelvinBot commented on Apr 13, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    This is a HybridApp-specific deadlock in the post-logout re-login flow. On HybridApp native, AppNavigator.native.tsx:15-21 requires both authenticated AND hybridApp.readyToShowAuthScreens to show auth screens (standalone only needs authenticated).

    The function signInToOldDotAndChooseExperience (src/libs/HybridApp.ts:75-124) is responsible for setting readyToShowAuthScreens = true after sign-in. It has a strict precondition at line 95 that requires account.requiresTwoFactorAuth and account.needsTwoFactorAuthSetup to not be undefined. However, during signInWithValidateCode (src/libs/actions/Session/index.ts:876), the optimistic data spreads DEFAULT_ACCOUNT_DATA ({errors: null, success: '', isLoading: false}) which does not include these 2FA fields — leaving them undefined.

    Additionally, at line 115, readyToShowAuthScreens is only set when tryNewDot !== undefined. But NVP_TRY_NEW_DOT is cleared by Onyx.clear() during logout and is only repopulated by the OpenApp API call, which runs inside AuthScreens (AuthScreensInitHandler.tsx:149). This creates a chicken-and-egg problem: AuthScreens needs readyToShowAuthScreens, which needs tryNewDot, which only comes from OpenApp, which only runs when AuthScreens mounts.

    The result: after sign-in completes (authToken is set, spinner stops), readyToShowAuthScreens remains false, so AppNavigator continues showing the sign-in page.

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

    The signInToOldDotAndChooseExperience function in src/libs/HybridApp.ts should handle the post-logout sign-in case where tryNewDot is undefined. When the user signs in via the NewDot sign-in page (useNewDotSignInPage === true) and all other preconditions are met, but tryNewDot is still undefined (because OpenApp hasn't been called yet), the function should set readyToShowAuthScreens = true to break the deadlock and allow AuthScreens to mount. Once AuthScreens mounts, OpenApp will fetch NVP_TRY_NEW_DOT and the app can then make the OldDot/NewDot routing decision.

    The early-return at line 95 checking for account.requiresTwoFactorAuth === undefined should also be reviewed — after a magic code sign-in where no 2FA is involved, these fields may legitimately be undefined in the server response, and the function should not block on them in that case.

    What alternative solutions did you explore? (Optional)

    1. Include NVP_TRY_NEW_DOT in the SigninUser API response — this would populate tryNewDot immediately after sign-in, avoiding the deadlock. However, this requires a backend change.
    2. Preserve NVP_TRY_NEW_DOT across logout by adding it to keysToPreserve in Onyx.clear() — simpler but may cause stale data issues if the user's OldDot/NewDot preference changed server-side.
    3. Include 2FA fields in DEFAULT_ACCOUNT_DATA (e.g., requiresTwoFactorAuth: false, needsTwoFactorAuthSetup: false) — this would prevent the early return at line 95 during the optimistic update phase. This is a reasonable complementary fix.
    Investigation details

    Key code locations:

    • src/libs/Navigation/AppNavigator/AppNavigator.native.tsx:15-21 — HybridApp auth gate
    • src/libs/HybridApp.ts:75-124 — signInToOldDotAndChooseExperience with early-return conditions
    • src/libs/actions/Session/index.ts:876 — optimistic data in signInWithValidateCode
    • src/CONST/index.ts:2221 — DEFAULT_ACCOUNT_DATA definition
    • src/libs/actions/SignInRedirect.ts:84-88 — logout clears Onyx then resets HybridApp state
    • src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx:149 — OpenApp call location

    Data flow during the bug:

    1. User logs out → Onyx.clear() removes HYBRID_APP, NVP_TRY_NEW_DOT, CREDENTIALS, ACCOUNT
    2. resetSignInFlow() sets readyToShowAuthScreens=false, useNewDotSignInPage=true
    3. User enters email + magic code → signInWithValidateCode fires
    4. Optimistic: account reset to DEFAULT_ACCOUNT_DATA (no 2FA fields), autoAuthState=SIGNING_IN
    5. signInToOldDotAndChooseExperience fires but returns early (SIGNING_IN + missing 2FA fields)
    6. Server responds: authToken set, autoAuthState=JUST_SIGNED_IN, credentials populated
    7. Function fires again but tryNewDot is still undefined (cleared during logout, only fetchable via OpenApp)
    8. Line 115: tryNewDot === undefined → setReadyToShowAuthScreens(true) never called → deadlock

    Additional risks found:

    • getHybridAppSettings() returns null on second call (HybridAppHandler.tsx:41-46)
    • signOutFromOldDot is called twice during logout (Session/index.ts:406 and SignInRedirect.ts:87)
    • isHybridAppSetupFinished (module-level var) is never reset on logout

    Possibly related: #82618 — "OD transition - Unable to log in to the app after logging out from OD" appears to describe a similar HybridApp post-logout login failure.


    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 Apr 13, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Apr 13, 2026
  5. melvin-bot commented on Apr 13, 2026

    @melvin-bot

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

  6. changed the title [-]Login - Unable to login to app once logout & attempt to login back[/-] [+][$250] Login - Unable to login to app once logout & attempt to login back[/+] on Apr 13, 2026
  7. melvin-bot commented on Apr 13, 2026

    @melvin-bot
  8. Ltbltbltbltb commented on Apr 13, 2026

    @Ltbltbltbltb

    Proposal

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

    On HybridApp (iOS), after logging out and re-authenticating with the same (or a different) email + magic code, the sign-in spinner disappears but the user is returned to the sign-in page instead of the app. The session is valid — only navigation is broken.

    What is the root cause of that problem?

    This is the same chicken-and-egg deadlock identified in #82618 and confirmed by the code:

    AppNavigator.native.tsx:20 gates auth screens behind authenticated && hybridApp?.readyToShowAuthScreens. readyToShowAuthScreens = true is called inside signInToOldDotAndChooseExperience (HybridApp.ts:120) — but only when tryNewDot !== undefined (line 115).

    After logout, Onyx.clear(keysToPreserve) is called with the list from App.ts:123-147. ONYXKEYS.NVP_TRY_NEW_DOT is not in that list, so it is wiped. On re-login, tryNewDot === undefined, the if at line 115 is never entered, readyToShowAuthScreens stays false, and AuthScreens never mounts. Since AuthScreens is where openApp is called (AuthScreensInitHandler.tsx:149), the value is never repopulated — completing the deadlock.

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

    Add ONYXKEYS.NVP_TRY_NEW_DOT to KEYS_TO_PRESERVE in App.ts:123:

    const KEYS_TO_PRESERVE: OnyxKey[] = [
        ONYXKEYS.ACCOUNT,
        ONYXKEYS.IS_CHECKING_PUBLIC_ROOM,
        ...
        ONYXKEYS.HYBRID_APP,
    +   ONYXKEYS.NVP_TRY_NEW_DOT,   // Preserve across logout so HybridApp routing isn't deadlocked on re-login
        ONYXKEYS.SHOULD_USE_STAGING_SERVER,
        ...
    ];

    Why this works: ONYXKEYS.CREDENTIALS is already preserved (keeping autoGeneratedLogin/autoGeneratedPassword). After re-login, signInToOldDotAndChooseExperience passes the line-95 guard (credentials set + 2FA fields populated by server response) and now also passes the tryNewDot !== undefined guard at line 115, calling setReadyToShowAuthScreens(true) — breaking the deadlock.

    Stale-data risk is bounded: openApp runs immediately after AuthScreens mounts and overwrites NVP_TRY_NEW_DOT with the authenticated user's fresh server value. The preserved stale value is only used for the routing decision in the brief window before openApp responds. For the common case (same user re-logging in) it is exactly correct. For a different account, it may briefly show the wrong experience, but openApp corrects it in the same session.

    This is consistent with the existing pattern: ONYXKEYS.HYBRID_APP is already preserved in this list and then immediately reset by resetSignInFlow().

    What alternative solutions did you explore? Why did you reject them?

    1. Add a special case in signInToOldDotAndChooseExperience for tryNewDot === undefined: Valid, but adds a conditional branch to auth routing logic and requires knowing whether to stay in NewDot or OldDot before that preference is known. The one-line KEYS_TO_PRESERVE change is semantically cleaner — the preference was already known from the previous session.

    2. Include requiresTwoFactorAuth: false in DEFAULT_ACCOUNT_DATA: Risky — the optimistic merge would temporarily set false for users who have 2FA enabled. The line-95 guard for 2FA fields is not the blocking issue: these fields are populated by the server's SignInUserWithLink response before tryNewDot becomes the gating factor.

    3. Backend change to include NVP_TRY_NEW_DOT in the SignInUserWithLink response: Correct fix long-term, but requires a backend change and is out of scope for this frontend bug.

  9. ikevin127 commented on Apr 14, 2026

    @ikevin127
    Contributor

    🟢 On production everything works as expected on iPhone 17 Pro Max - iOS 26.4, app version v9.3.37-10:

    ScreenRecording_04-13-2026.18-03-18_1.MP4

    🟡 However on local Dev / iPhone 17 Pro Max Simulator - iOS 26.2, app version v9.3.59-2, I'm also not able to reproduce the issue with blocked after inputting the magic code, but there's another issue on my side where I'm not able to logout, unless I close and reopen the app (then I'm logged out - land on sign-in page):

    Simulator.Screen.Recording.-.iPhone.17.Pro.Max.-.2026-04-13.at.18.13.43.mov

    Given I'm not able to reproduce the issue, I'm also not able to verify whether any of the proposed solutions actually do something - this might need a retest from QA on latest versions and if still consistently reproducible: assign to another C+ that's able to actually reproduce and verify the solutions ✅

    🎀👀🎀 C+ reviewed

  10. melvin-bot commented on Apr 14, 2026

    @melvin-bot

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

  11. grgia commented on Apr 14, 2026

    @grgia
    Contributor

    Cannot reproduce either, closing

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