Skip to content

[Due for payment 2025-08-26] [BACK BUTTON] [$250] Sign In - App closes when tapped on device back button on "Enter magic code" screen #67883

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.1.89-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: Exploratory
Email or phone of affected tester (no customers): applausetester+omqq1@applause.expensifail.com
Issue reported by: Applause Internal Team
Device used: Pixel 6/Android 16
App Component: User Settings

Action Performed:

Precondition: user signed out

  1. Open app
  2. Write any registered email and tap on "Next" button
  3. Tap device back button to close keyboard
  4. Tap again device back button to navigate to previous page

Expected Result:

User should be navigated to previous screen "Enter your email"

Actual Result:

App closes when tapped on device back button on "Enter magic code" screen

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021955039225588208628
  • Upwork Job ID: 1955039225588208628
  • Last Price Increase: 2025-08-11
Issue OwnerCurrent Issue Owner: @muttmuure

Activity

  1. added
    Daily
    Bug
    on Aug 5, 2025
  2. melvin-bot commented on Aug 5, 2025

    @melvin-bot

    Triggered auto assignment to @muttmuure (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. Krishna2323 commented on Aug 5, 2025

    @Krishna2323
    Contributor

    Proposal

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

    Sign In - App closes when tapped on device back button on "Enter magic code" screen

    What is the root cause of that problem?

    • The code input is not using a different page than the base signin page, it's just overlayed above the email input page, so using device back button closes the app:
      {shouldShowValidateCodeForm && (
      <ValidateCodeForm
      isVisible={!shouldShowAnotherLoginPageOpenedMessage}
      isUsingRecoveryCode={isUsingRecoveryCode}
      setIsUsingRecoveryCode={setIsUsingRecoveryCode}
      ref={validateCodeFormRef}
      />
      )}

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

    • We should use useHandleBackButton and pass navigateBack for the parameter.
      const navigateBack = () => {
      if (
      shouldShouldSignUpWelcomeForm ||
      (!shouldShowAnotherLoginPageOpenedMessage &&
      (shouldShowEmailDeliveryFailurePage || shouldShowUnlinkLoginForm || shouldShowChooseSSOOrMagicCode || shouldShowSMSDeliveryFailurePage))
      ) {
      clearSignInData();
      return;
      }
      if (shouldShowValidateCodeForm) {
      validateCodeFormRef.current?.clearSignInData();
      return;
      }
      Navigation.goBack();
      };
        const navigateBack = () => {
            if (
                shouldShouldSignUpWelcomeForm ||
                (!shouldShowAnotherLoginPageOpenedMessage &&
                    (shouldShowEmailDeliveryFailurePage || shouldShowUnlinkLoginForm || shouldShowChooseSSOOrMagicCode || shouldShowSMSDeliveryFailurePage))
            ) {
                clearSignInData();
                return true;
            }
    
            if (shouldShowValidateCodeForm) {
                validateCodeFormRef.current?.clearSignInData();
                return true;
            }
    
            Navigation.goBack();
            return false;
        };
        useImperativeHandle(ref, () => ({
            navigateBack,
        }));
    
        useHandleBackButton(navigateBack);

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    N/A

    What alternative solutions did you explore? (Optional)

    • We can use useBeforeRemove hook to listen for beforeRemove and pass navigateBack to it. Or we can combine both.

    • If we also want to handle this on web/mweb then we need to do listen for window.addEventListener('popstate') just like we do in Modal,

    • This is just pseudocode, we should also check for other state of the for like, we do in the navigateBack and only add the listener when the email input is not visible (any other component is visible, e.g. UnlinkLoginForm, ChooseSSOOrMagicCode.) We can use useEffect hook to remove and add the listener.

        const handlePopStateRef = useRef(() => {
            navigateBack();
        });
    
        const AddListener = () => {
            window.history.pushState({shouldGoBack: true}, '', null);
            window.addEventListener('popstate', handlePopStateRef.current);
        };
    
        useEffect(
            () => () => {
                window.removeEventListener('popstate', handlePopStateRef.current);
            },
            [],
        );
    
        if (shouldShowValidateCodeForm) {
            AddListener?.();
        }

    Result

    Monosnap.screencast.2025-08-05.16-12-49.mp4
    Monosnap.screencast.2025-08-05.17-01-30.mp4
  4. melvin-bot commented on Aug 8, 2025

    @melvin-bot

    @muttmuure Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  5. added
    External
    on Aug 11, 2025
  6. melvin-bot commented on Aug 11, 2025

    @melvin-bot
  7. changed the title [-]Sign In - App closes when tapped on device back button on "Enter magic code" screen[/-] [+][$250] Sign In - App closes when tapped on device back button on "Enter magic code" screen[/+] on Aug 11, 2025
  8. added
    Help Wanted
    on Aug 11, 2025
  9. melvin-bot commented on Aug 11, 2025

    @melvin-bot

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

  10. hungvu193 commented on Aug 12, 2025

    @hungvu193
    Contributor

    Thanks @Krishna2323. I think that's fine to handle it for Android only.

    If we use the browser history popState solution, it can lead to forward browser button doing nothing after we press browser go back button because we push an empty state onto it. I used to experience the same case while working on this TestToolModal bug, we later decided to migrate it to Modal Screen.

    Let's move forward with your main solution

    🎀 👀 🎀

  11. 31 remaining items

  12. twisterdotcom commented on Sep 11, 2025

    @twisterdotcom
    Contributor

    Hello assignees. We came to the conclusion in #57969 that the back buttons in the app behave inconsistently and in a way that we don't think is ideal, but that fixing the issue is a potentially high cost, low reward situation. We are going to start tracking these issues and attempt to find a way and somebody who can help solve this problem heuristically across the app.

    I have HELD a lot of issues related to the "back button" but any that are currently Reviewing or Due for payment I have not held. If you believe your issue shouldn't be linked or HELD, comment with the explanation and I will review and unlike/remove the hold. Thank you!

  13. hungvu193 commented on Sep 12, 2025

    @hungvu193
    Contributor

    Hi @twisterdotcom This issue was due for payment since Aug 26th

  14. twisterdotcom commented on Sep 12, 2025

    @twisterdotcom
    Contributor

    @muttmuure is this all paid out now?

  15. muttmuure commented on Sep 12, 2025

    @muttmuure
    Contributor

    @hungvu193 is also owed payment via NewDot, sorry I blitzed through all of these yesterday and didn't catch it

  16. muttmuure commented on Sep 12, 2025

    @muttmuure
    Contributor

    @hungvu193 did you request payment already?

  17. hungvu193 commented on Sep 12, 2025

    @hungvu193
    Contributor

    @hungvu193 did you request payment already?

    I did. Feel free to close

  18. JmillsExpensify commented on Sep 16, 2025

    @JmillsExpensify
    Contributor

    $250 approved for @hungvu193

  19. quinthar commented on Sep 17, 2025

    @quinthar
    Contributor

    Approved $250 for @Krishna2323

  20. added and removed
    Weekly
    on Oct 13, 2025
  21. melvin-bot commented on Oct 13, 2025

    @melvin-bot

    This issue has not been updated in over 15 days. @hungvu193, @lakchote, @muttmuure, @Krishna2323 eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  22. melvin-bot commented on Dec 10, 2025

    @melvin-bot

    @hungvu193, @lakchote, @muttmuure, @Krishna2323, this Monthly task hasn't been acted upon in 6 weeks; closing.

    If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.

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

Metadata

Metadata

Labels

Awaiting PaymentBugExternalMonthlyNot a priorityReviewing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions