fix: clean up login tokens in users.deactivateidle#40566
Conversation
🦋 Changeset detectedLatest commit: c263291 The changes in this PR will be included in the next version bump. This PR includes changesets to release 40 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 |
There was a problem hiding this comment.
1 issue found across 5 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/meteor/app/api/server/v1/users.ts">
<violation number="1" location="apps/meteor/app/api/server/v1/users.ts:431">
P2: This notifies all pre-fetched IDs even if some were not actually updated, which can emit incorrect `active: false` and login-token diffs under concurrent logins.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Re-trigger cubic
| const ids = await Users.findActiveNotLoggedInAfterWithRole(lastLoggedIn, role, { projection: { _id: 1 } }) | ||
| .map(({ _id }: { _id: string }) => _id) | ||
| .toArray(); | ||
|
|
||
| const { modifiedCount: count } = await Users.setActiveNotLoggedInAfterWithRole(lastLoggedIn, role, false); | ||
|
|
||
| ids.forEach((_id) => { | ||
| void notifyOnUserChange({ | ||
| clientAction: 'updated', | ||
| id: _id, | ||
| diff: { 'services.resume.loginTokens': [], 'active': false }, | ||
| }); | ||
| }); |
There was a problem hiding this comment.
P2: This notifies all pre-fetched IDs even if some were not actually updated, which can emit incorrect active: false and login-token diffs under concurrent logins.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/meteor/app/api/server/v1/users.ts, line 431:
<comment>This notifies all pre-fetched IDs even if some were not actually updated, which can emit incorrect `active: false` and login-token diffs under concurrent logins.</comment>
<file context>
@@ -428,9 +428,20 @@ API.v1.addRoute(
lastLoggedIn.setDate(lastLoggedIn.getDate() - daysIdle);
- // since we're deactiving users that are not logged in, there is no need to send data through WS
+ const ids = await Users.findActiveNotLoggedInAfterWithRole(lastLoggedIn, role, { projection: { _id: 1 } })
+ .map(({ _id }: { _id: string }) => _id)
+ .toArray();
</file context>
| const ids = await Users.findActiveNotLoggedInAfterWithRole(lastLoggedIn, role, { projection: { _id: 1 } }) | |
| .map(({ _id }: { _id: string }) => _id) | |
| .toArray(); | |
| const { modifiedCount: count } = await Users.setActiveNotLoggedInAfterWithRole(lastLoggedIn, role, false); | |
| ids.forEach((_id) => { | |
| void notifyOnUserChange({ | |
| clientAction: 'updated', | |
| id: _id, | |
| diff: { 'services.resume.loginTokens': [], 'active': false }, | |
| }); | |
| }); | |
| const ids = await Users.findActiveNotLoggedInAfterWithRole(lastLoggedIn, role, { projection: { _id: 1 } }) | |
| .map(({ _id }: { _id: string }) => _id) | |
| .toArray(); | |
| const { modifiedCount: count } = await Users.setActiveNotLoggedInAfterWithRole(lastLoggedIn, role, false); | |
| const deactivatedIds = (await Users.findByIds(ids, { projection: { _id: 1, active: 1 } }).toArray()) | |
| .filter(({ active }) => active === false) | |
| .map(({ _id }) => _id); | |
| deactivatedIds.forEach((_id) => { | |
| void notifyOnUserChange({ | |
| clientAction: 'updated', | |
| id: _id, | |
| diff: { 'services.resume.loginTokens': [], 'active': false }, | |
| }); | |
| }); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release-8.0.6 #40566 +/- ##
================================================
Coverage ? 70.67%
================================================
Files ? 3168
Lines ? 109517
Branches ? 19667
================================================
Hits ? 77399
Misses ? 30077
Partials ? 2041
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Backport of #40496