Fix duplicate SignInWithSupportAuthToken call during support login#91200
Fix duplicate SignInWithSupportAuthToken call during support login#91200MelvinBot wants to merge 6 commits into
Conversation
Add setLastShortAuthToken call to signInWithSupportAuthToken to prevent the dedup guard in LogInWithShortLivedAuthTokenPage from being bypassed. Without this, both LogInWithShortLivedAuthTokenPage and LogOutPreviousUserPage fire signInWithSupportAuthToken independently, causing a 4th Auth call that triggers the 3/30s throttle. Co-authored-by: Daniel Silva <danieldoglas@users.noreply.github.com>
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@MelvinBot add unit tests for this. |
Verify that signInWithSupportAuthToken stores the auth token via NetworkStore.setLastShortAuthToken (for the dedup guard) and makes the correct API call. Co-authored-by: Daniel Silva <danieldoglas@users.noreply.github.com>
|
Added two unit tests for
All 31 tests in the suite pass. |
…tion Co-authored-by: Daniel Silva <danieldoglas@users.noreply.github.com>
|
Fixed the failing spellcheck: replaced the word |
… no-unsafe-assignment Co-authored-by: Daniel Silva <danieldoglas@users.noreply.github.com>
|
Fixed the failing ESLint check: added |
| test('should make the SignInWithSupportAuthToken API call', () => { | ||
| // eslint-disable-next-line rulesdir/no-multiple-api-calls | ||
| const readSpy = jest.spyOn(API, 'read'); | ||
| const testToken = 'supportAuthToken456'; | ||
|
|
||
| SessionUtil.signInWithSupportAuthToken(testToken); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
| expect(readSpy).toHaveBeenCalledWith('SignInWithSupportAuthToken', {authToken: testToken}, expect.objectContaining({optimisticData: expect.any(Array)})); | ||
|
|
||
| readSpy.mockRestore(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
@MelvinBot this is not a good test for our initial problem. Maybe this should be an UI test that tests the navigations between the two pages?
There was a problem hiding this comment.
Good point! Replaced the unit tests with a UI test in tests/ui/SessionTest.tsx that renders the full <App /> with a support auth token deep link and verifies signInWithSupportAuthToken is called exactly once during the LogInWithShortLivedAuthTokenPage → LogOutPreviousUserPage navigation transition. This directly tests the dedup guard in the real navigation flow.
…up guard Remove the simple unit tests that only checked setLastShortAuthToken is called, and add a UI test that renders the full App with a support auth token deep link to verify signInWithSupportAuthToken is called exactly once during the LogInWithShortLivedAuthTokenPage → LogOutPreviousUserPage navigation flow. Co-authored-by: Daniel Silva <danieldoglas@users.noreply.github.com>
|
MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR. Next steps: A human should review the recent commits and resolve the conflicting CI errors manually. |
1 similar comment
|
MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR. Next steps: A human should review the recent commits and resolve the conflicting CI errors manually. |
| }); | ||
|
|
||
| it('should not call signInWithSupportAuthToken twice when navigating from LogInWithShortLivedAuthTokenPage to LogOutPreviousUserPage', async () => { | ||
| expect(hasAuthToken()).toBe(false); |
There was a problem hiding this comment.
@MelvinBot there needs to be a logged user for this flow to call the api twice.
There was a problem hiding this comment.
Good catch! Updated the test to first sign in a user (so the app starts on AuthScreens), unmount, then set the support auth token deep link and remount. This way both LogOutPreviousUserPage (AuthScreens) and LogInWithShortLivedAuthTokenPage (PublicScreens) are exercised, matching the real bug scenario. The test verifies signInWithSupportAuthToken is still only called once thanks to the dedup guard.
The bug requires a logged-in user for both LogInWithShortLivedAuthTokenPage and LogOutPreviousUserPage to fire. Updated the test to sign in a user, unmount, set the support deep link, then remount - matching the real bug scenario. Also fixed mock recursion by restoring all mocks before re-spying. Co-authored-by: Daniel Silva <danieldoglas@users.noreply.github.com>
Explanation of Change
signInWithSupportAuthTokenwas missing aNetworkStore.setLastShortAuthToken(authToken)call thatsignInWithShortLivedAuthTokenalready has. Without it, the dedup guard inLogInWithShortLivedAuthTokenPage(token === getLastShortAuthToken()) never matches for support tokens, so bothLogInWithShortLivedAuthTokenPage(PublicScreens) andLogOutPreviousUserPage(AuthScreens) independently firesignInWithSupportAuthToken, making 2 calls instead of one.This one-line addition matches the existing pattern in
signInWithShortLivedAuthTokenand makes the dedup guard effective for support tokens.Fixed Issues
$ https://github.com/Expensify/Expensify/issues/383021
Tests
// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.
Offline tests
N/A - this change only affects the support login transition flow which requires network connectivity.
QA Steps
// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari