fix: stale client session and cache after the logged-in user is deleted - #42041
fix: stale client session and cache after the logged-in user is deleted#42041KevLehman wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 873370d The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #42041 +/- ##
========================================
Coverage 69.32% 69.33%
========================================
Files 4287 4287
Lines 171470 171471 +1
Branches 31117 31108 -9
========================================
+ Hits 118880 118891 +11
+ Misses 47411 47400 -11
- Partials 5179 5180 +1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Deleting a logged-in user never cleared the session on the client: the userData stream 'removed' event only dropped the user record, leaving the login token in localStorage and the cached stores populated. Logging back in as a recreated user then failed once (the login call carried the dead token) and, on retry, merged the new subscriptions onto the stale ones, duplicating every auto-joined channel in the sidebar until a hard refresh. Drop the stored credentials on the 'removed' event, and reset the cached store before a full server load so a cache miss never merges onto records left by a previous session.
98c3d1d to
873370d
Compare
Proposed changes (including videos or screenshots)
Deleting a logged-in user never cleared the session in the browser. The
userDatastreamremovedevent only dropped the user record from the store, leaving the login token in localStorage,Meteor.userId()set and the cached stores (subscriptions, rooms, ...) populated. Nothing else notices in time: nobody callslogout, and the login-token observe that would close the socket polls every 10s (disable-oplog), well after the user has already logged back in.Two consequences when logging back in as a recreated user on the same page, both stale cache:
loginattempt fails with "You must be logged in to do this." becauseddpOverRESTattaches the deleted user's token from localStorage to the method call.storeManymerges the new records onto the previous session's records still in memory. New subscriptions have new_ids and the samerid, so every auto-joined channel appears twice in the sidebar until a hard refresh.Changes:
client/lib/userData.ts: callclearStoredCredentials()on the own-userremovedevent, the same dead-session handling already used byRestApiClient,ddpOverRESTandstartup.ts. Drops the stale token and nulls the connection userId, so the next login goes out unauthenticated and succeeds on the first attempt.client/lib/cachedStores/CachedStore.ts: reset the store before a full<name>/getload. A full load is authoritative, so a cache miss must never merge onto records left by a previous session, whatever path left them there.Tests:
CachedStore.spec.ts(jest): stale record in memory + full load from server keeps only the server records. Failed before the fix.sidebar-after-user-recreation.spec.ts(Playwright): seed a user and a live session via API, delete the user via API, recreate it, log in on the same page without reloading, assertgeneralis listed once. Failed before the fix at the login step; passes in under a second with it (3/3 locally).Issue(s)
Steps to test or reproduce
Before: first login attempt errors, second attempt shows every auto-joined channel twice in the sidebar. After: login succeeds on the first attempt and each channel is listed once.
Further comments
No Meteor internals involved.
Accounts.onLogouthooks do not fire on this path, same as the otherclearStoredCredentialscallers today.