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

Ensure sessions and tokens are synced between tabs #2498

Merged
merged 2 commits into from
Jan 12, 2024
Merged

Conversation

estrattonbailey
Copy link
Member

This should address the multiple reports of unexpected signouts.

The issue was with users using multiple tabs on web. Both tabs would retain the same refreshJwt in memory, and refresh tokens can be used only once. So once a refresh token was rotated in tab A, the tab B was notified but did not update that token on the agent, and so when tab B tried to get a new access token, refreshSession would fail.

This was a little tricky to pinpoint because if both tabs were periodically reloaded within the access token expiry window, our session handling would pick up the new refresh token from storage and continue as normal for a time. So this issue only existed in long-running multi-tab sessions.

{},
logger.DebugContext.session,
)
logger.warn(`session: clear current account`)
Copy link
Member Author

Choose a reason for hiding this comment

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

Sending these to Sentry so we can monitor for spikes

@@ -322,8 +318,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
)

const logout = React.useCallback<ApiContext['logout']>(async () => {
logger.info(`session: logout`)
Copy link
Member Author

Choose a reason for hiding this comment

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

Will be included in any session: clear current account warnings

@@ -551,41 +547,59 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
return persisted.onUpdate(() => {
const session = persisted.get('session')

logger.debug(`session: onUpdate`, {}, logger.DebugContext.session)
logger.info(`session: persisted onUpdate`, {})
Copy link
Member Author

Choose a reason for hiding this comment

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

Sending these to Sentry as breadcrumbs so we know if a broadcast resulted in a logout

Comment on lines +596 to +600
setState(s => ({
...s,
accounts: session.accounts,
currentAccount: session.currentAccount,
}))
Copy link
Member Author

@estrattonbailey estrattonbailey Jan 11, 2024

Choose a reason for hiding this comment

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

We don't directly access tokens anywhere atm, but I thought it made sense to keep each tab's React state in sync too so we don't surprise ourselves later.

Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

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

Looks good. Will test by leaving open in my dev env all day

@pfrazee pfrazee merged commit 11f6ff7 into main Jan 12, 2024
4 checks passed
@pfrazee pfrazee deleted the eric/session-sync branch January 12, 2024 18:40
estrattonbailey added a commit that referenced this pull request Jan 18, 2024
* origin/main: (44 commits)
  Patch `@lingui/core` to fix `unraw` import resolution error (#2548)
  1.65
  Fix the fallback to discover behavior on the home feed (#2546)
  Bump android version code
  Bump ios build number
  Add a new home feed-api wrapper and give a header indicating the fallback behavior (#2534)
  Add accept-language header (#2457)
  rss: filter out replies server-side (#2518)
  feat: show muted/blocked status on list card (#2523)
  1.64 (#2521)
  Bump [email protected] (#2519)
  Create a profile record on new user (#2520)
  fix: truncate long email address (#2493)
  fix: set html lang according to app language (#2496)
  Ensure sessions and tokens are synced between tabs (#2498)
  package.json: cp --verbose doesn't exist on macos (#2501)
  Suggest post language correction (#2486)
  (optional) In app browser  (#2490)
  Toggle minimal shell on any scroll for web (#2499)
  ✨ New report type, appeal (#2455)
  ...
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.

2 participants