Skip to content

Stop a client-side session age check from signing users out and dropping GPS trips - #97787

Open
allgandalf wants to merge 23 commits into
Expensify:mainfrom
allgandalf:gps-trip-survives-forced-reauth
Open

Stop a client-side session age check from signing users out and dropping GPS trips#97787
allgandalf wants to merge 23 commits into
Expensify:mainfrom
allgandalf:gps-trip-survives-forced-reauth

Conversation

@allgandalf

@allgandalf allgandalf commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

isExpiredSession is a 2 hour client-side check on session.creationDate that never looks at whether the token is actually valid. On a SAML account it sends reauthenticate() straight to redirectToSignIn, and the Onyx.clear there wipes the in-progress GPS trip. Attachment images now keep serving the token we already have when a background refresh is not possible, and a live trip survives the forced re-auth, owner-checked so another user can never resume it.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/665676
$ #92435
PROPOSAL: n/a

Tests

Both halves need an account that cannot silently reauthenticate, i.e. SAML required. On a normal account reauthenticate() succeeds in the background, so nothing here changes.

Attachment images:

  1. Sign in on a SAML required account.
  2. Set session.creationDate more than 2 hours into the past. Leave the auth token untouched, it is still valid.
  3. Open a chat containing a receipt or image attachment.
  4. Verify the attachment renders and you stay signed in. On main the app signs you out to the IdP at this point.

GPS trip, on iOS or Android:
5. Start a distance expense, pick the GPS tab and start a trip, then let it record some distance.
6. Go to Settings > Troubleshoot > Authentication status, tap Invalidate with delay and wait ~15 seconds. Test tools are hidden on production, so use dev or staging.
7. Complete the SAML sign in as the same user.
8. Verify the Continue GPS trip recording? prompt appears and that Continue trip resumes with the earlier distance intact.
9. Repeat steps 5 and 6, then cancel the IdP browser when it opens and sign in as a different user.
10. Verify no trip prompt appears and the previous user's route is not shown.

  • Verify that no errors appear in the JS console

Offline tests

  1. Start a GPS trip and go offline.
  2. Verify the trip keeps recording and no sign in redirect happens. The image path already returns the stored token while offline, so this path is unchanged.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-08-12.at.15.17.37.mov

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/Image/getImageSource.ts 100.00% <100.00%> (ø)
src/components/Image/index.tsx 64.61% <ø> (ø)
src/libs/actions/SignInRedirect.ts 81.48% <100.00%> (+7.89%) ⬆️
src/libs/actions/GPSDraftDetails.ts 0.00% <0.00%> (ø)
.../actions/Session/AttachmentImageReauthenticator.ts 36.00% <0.00%> (ø)
...tep/IOURequestStepDistanceGPS/GPSButtons/index.tsx 0.00% <0.00%> (ø)
...rc/components/GPSTripStateChecker/index.native.tsx 75.51% <80.00%> (+0.51%) ⬆️
src/libs/Reauthentication.ts 70.43% <71.42%> (+0.06%) ⬆️
... and 12 files with indirect coverage changes

@allgandalf
allgandalf marked this pull request as ready for review August 12, 2026 09:51
@allgandalf
allgandalf requested review from a team as code owners August 12, 2026 09:51
@melvin-bot
melvin-bot Bot requested review from Eskalifer1 and joekaufmanexpensify and removed request for a team August 12, 2026 09:51
@melvin-bot

melvin-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

@Eskalifer1 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team August 12, 2026 09:51
@github-actions
github-actions Bot requested review from luacmartins and tgolen August 12, 2026 09:51
@github-actions

Copy link
Copy Markdown
Contributor

This PR adds a new Onyx.connectWithoutView call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @luacmartins) — a review from any one of them is enough. Please add a link in your PR description to the Slack discussion where the @frontend-performance team approved using connectWithoutView here.

@Eskalifer1

Copy link
Copy Markdown
Contributor

LMK if you need my help here!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08fac85824

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/actions/Session/AttachmentImageReauthenticator.ts Outdated
Comment thread src/libs/actions/Session/AttachmentImageReauthenticator.ts Outdated
Comment thread src/libs/actions/SignInRedirect.ts Outdated

@GCyganek GCyganek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one comment, other than that it looks good 👍 I tested GPS flows and they seem to be working fine

Comment thread src/components/GPSTripStateChecker/index.native.tsx Outdated
@allgandalf

Copy link
Copy Markdown
Contributor Author

LMK if you need my help here!

@Eskalifer1 do you have SAML enabled ?

@Eskalifer1

Copy link
Copy Markdown
Contributor

do you have SAML enabled ?

No, i don't. Is there any way to setup it?

@allgandalf

Copy link
Copy Markdown
Contributor Author

do you have SAML enabled ?

No, i don't. Is there any way to setup it?

not that i know off, you need a private domain, be domain admin and SAML enabled :_;

@Eskalifer1

Copy link
Copy Markdown
Contributor

Oh, okay. Feel free to reassign this, thank you for quich answer!

Comment thread src/libs/actions/SignInRedirect.ts Outdated

@joekaufmanexpensify joekaufmanexpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for product

@mountiny

Copy link
Copy Markdown
Contributor

conflicts

@quinthar quinthar removed the #migrate label Aug 13, 2026
Comment thread src/components/GPSTripStateChecker/index.native.tsx Outdated
@mountiny
mountiny requested a review from tgolen August 13, 2026 13:09
@mountiny

Copy link
Copy Markdown
Contributor

Thanks for updating that @allgandalf

@Eskalifer1 What is your ETA for reviewing and testing this PR?

@Eskalifer1

Copy link
Copy Markdown
Contributor

Hi @mountiny, i don't have SAML enabled, i have asked here(#97787 (comment)) to reassign

@mountiny

Copy link
Copy Markdown
Contributor

Ah right @allgandalf I am not sure if contributors can test this, their saml login will take them to production, right?

@allgandalf

Copy link
Copy Markdown
Contributor Author

Ah right @allgandalf I am not sure if contributors can test this, their saml login will take them to production, right?

Correct! Not really sure what is the best way here

@allgandalf

Copy link
Copy Markdown
Contributor Author

maybe, lets production QA this then ?

Comment thread src/components/GPSTripStateChecker/index.native.tsx Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants