Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[$125] mWeb - 2FA - In 2FA magic code page, after refresh briefly error message is displayed #54009

Open
1 of 8 tasks
IuliiaHerets opened this issue Dec 12, 2024 · 10 comments
Open
1 of 8 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors

Comments

@IuliiaHerets
Copy link

IuliiaHerets commented Dec 12, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: V9. 0.75-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
Issue reported by: Applause Internal Team
Device used: Redmi note 10s android 13
App Component: User Settings

Action Performed:

Pre-condition: Login with unverified gmail account

  1. Go to https://staging.new.expensify.com/home
  2. Go to settings- security - two factor authentication
  3. Enter incorrect magic code
  4. Refresh the page

Expected Result:

In 2FA magic code page, after refresh briefly error message must not be displayed.

Actual Result:

In 2FA magic code page, after refresh briefly error message is displayed.

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6691899_1733991788664.Screenrecorder-2024-12-12-13-48-04-520.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021867646284163514204
  • Upwork Job ID: 1867646284163514204
  • Last Price Increase: 2024-12-13
Issue OwnerCurrent Issue Owner: @dominictb
@IuliiaHerets IuliiaHerets added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Dec 12, 2024
Copy link

melvin-bot bot commented Dec 12, 2024

Triggered auto assignment to @OfstadC (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.

@FitseTLT
Copy link
Contributor

FitseTLT commented Dec 12, 2024

Edited by proposal-police: This proposal was edited at 2024-12-12 13:36:14 UTC.

Proposal

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

2FA - In 2FA magic code page, after refresh briefly error message is displayed

What is the root cause of that problem?

When the page is refreshed while there were error previously the error will only be cleared after the server response of the resend validate code requested here

useEffect(() => {
if (!firstRenderRef.current || !isVisible || hasMagicCodeBeenSent) {
return;
}
firstRenderRef.current = false;
sendValidateCode();

so it will take a while to get cleared

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

We should clear errors on mount (or unmount/useBeforeRemove) just like we clear when user start entering code here

const onTextInput = useCallback(
(text: string) => {
setValidateCode(text);
setFormError({});
if (!isEmptyObject(validateError)) {
clearError();
User.clearValidateCodeActionError('actionVerified');
}

We can do that in BaseValidateCodeForm for more general fix like:

useEffect(() => {
        if (!isEmptyObject(validateError)) {
            clearError();
            User.clearValidateCodeActionError('actionVerified');
        }
    }, []);

Optionally, we might also similarly clear the error here too so that the error will be cleared immediately instead of waiting for BE response on pressing Didn't receive a magic code button

Alternatively, we can clear the errors on mount or before sendValidateCode here

Despite the claim by the below proposal here is a demo that clearing error on mount approach works well on mobile:
2024-12-12.17-44-00.mp4
### What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

What alternative solutions did you explore? (Optional)

We can also consider clearing errors on User.requestValidateCodeAction but this function is used in several other places and the errors are different in different instances so we can pass clearError callback to the function and run the respective callbacks on the start of the function to clear errors before requesting code resend is requested so that we don't wait to clear errors for the BE response.

@nyomanjyotisa
Copy link
Contributor

Proposal

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

In 2FA magic code page, after refresh briefly error message is displayed

What is the root cause of that problem?

On reload page we need to wait for API call response to clear the errors

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

Clear the errors on mount and on unmount using useEffect hook

    useEffect(() => {
        clearError();

        return () => {
            clearError();
        };
    }, []);

And only allow to show error if validateAndSubmitForm executed, since clearing the errors on mount and on unmount alone still briefly show the error in mWeb Android & iOS(#52303 (comment)). We did the same approach here #52303

const [canShowError, setCanShowError] = useState<boolean>(false);

const validateAndSubmitForm = useCallback(() => {

const validateAndSubmitForm = useCallback(() => {
        setCanShowError(true);

errorText={formError?.validateCode ? translate(formError?.validateCode) : ErrorUtils.getLatestErrorMessage(account ?? {})}
hasError={!isEmptyObject(validateError)}

errorText={canShowError ? formError?.validateCode ? translate(formError?.validateCode) : ErrorUtils.getLatestErrorMessage(account ?? {}) : ''}
hasError={canShowError ? !isEmptyObject(validateError) : false}

errors={canShowError ? validateError : undefined}

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)

N/A

@huult
Copy link
Contributor

huult commented Dec 12, 2024

Edited by proposal-police: This proposal was edited at 2024-12-12 16:40:23 UTC.

Proposal

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

In 2FA magic code page, after refresh briefly error message is displayed

What is the root cause of that problem?

We sent an incorrect magic code to the API, which responds with errorFields, and it is then stored in Onyx.

  • Screenshot 2024-12-12 at 22 43 42
  • Screenshot 2024-12-12 at 22 49 17

const validateLoginError = ErrorUtils.getEarliestErrorField(loginData, 'validateLogin');

When refreshing the 2FA page, the errorFields data still exists (the error is still displayed). After reloading, ResendValidateCode is called. If ResendValidateCode responds without errorFields, the ONYXKEYS.LOGIN_LIST is updated, and the error is removed. However, if ResendValidateCode returns a 402 (sent too many times) error, the errorFields cannot be removed, and the error remains displayed.

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

The validateError appears when we input a valid magic code (6 digits) and submit it to the API for verification. When the page is reloaded, the code is removed. I think we should check if the magic code exists and is valid. If so, we should display the validateError. If it does not exist or is invalid, we should also display the validateError. This will resolve the issue.

Add this code to check validate code valid in BaseValidateCodeForm

    const isValidateCodeValid = !!validateCode.trim() || !!ValidationUtils.isValidValidateCode(validateCode);

To

 errors={isValidateCodeValid ? validateError : undefined}

To

  hasError={!isEmptyObject(isValidateCodeValid ? validateError : undefined)}
POC
Screen.Recording.2024-12-12.at.23.38.05.mov

Test branch

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

This is UI bug no need the test

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@OfstadC
Copy link
Contributor

OfstadC commented Dec 13, 2024

I'm currently OoO - but will be back on Tuesday - Reassigning to get the ball rolling, but happy to take back on Tuesday

@OfstadC OfstadC added Bug Something is broken. Auto assigns a BugZero manager. and removed Bug Something is broken. Auto assigns a BugZero manager. labels Dec 13, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

Triggered auto assignment to @michaelkwardrop (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.

@michaelkwardrop michaelkwardrop changed the title mWeb - 2FA - In 2FA magic code page, after refresh briefly error message is displayed [$125] mWeb - 2FA - In 2FA magic code page, after refresh briefly error message is displayed Dec 13, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

⚠️ Could not update price automatically because there is no linked Upwork Job ID. The BZ team member will need to update the price manually in Upwork.

@michaelkwardrop michaelkwardrop added the External Added to denote the issue can be worked on by a contributor label Dec 13, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

Job added to Upwork: https://www.upwork.com/jobs/~021867646284163514204

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 13, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

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

@michaelkwardrop
Copy link
Contributor

@dominictb please attempt reproduction and review the above proposals - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors
Projects
Development

No branches or pull requests

7 participants