Skip to content

Conversation

@ggazzo
Copy link
Member

@ggazzo ggazzo commented Jan 27, 2026

extracted from #38354

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation and error handling for missing, federated, or invalid rooms and users.
    • Strengthened two-factor flows with runtime checks and fallback verification.
  • Refactor

    • Standardized passing full user objects across APIs and internal flows for consistency.
    • Consolidated token invalidation and removed obsolete token utility.
    • Simplified event triggers to use resolved user context.
  • Tests

    • Updated tests to expect full user objects in erase flows.

✏️ Tip: You can customize this high-level summary in your review settings.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jan 27, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is targeting the wrong base branch. It should target 8.2.0, but it targets 8.1.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Jan 27, 2026

⚠️ No Changeset found

Latest commit: 7bda6f6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

Walkthrough

Replaces many userId string parameters with full user objects across server APIs and methods; rewrites twoFactorRequired as a const higher-order wrapper with AuthenticatedContext and runtime two-factor extraction/validation; updates related call sites, type signatures, and tests.

Changes

Cohort / File(s) Summary
Two-Factor & Auth Context
apps/meteor/app/2fa/server/twoFactorRequired.ts
Replaces twoFactorRequired function with a const HOF, adds AuthenticatedContext type, adapts this-type inference, extracts/validates two-factor args at runtime (including fallback checkCodeForUser), and preserves original signature via trailing type assertion.
Room & Team Erasure
apps/meteor/server/lib/eraseRoom.ts, apps/meteor/app/api/server/lib/eraseTeam.ts, apps/meteor/app/api/server/lib/eraseTeam.spec.ts
eraseRoom now accepts a user object (AtLeast<IUser,...>); eraseTeamShared made generic over user type and forwards user object to erase-room callbacks; test updated to expect full user object.
API Routes — eraseRoom callers
apps/meteor/app/api/server/v1/channels.ts, apps/meteor/app/api/server/v1/groups.ts, apps/meteor/app/api/server/v1/im.ts, apps/meteor/app/api/server/v1/rooms.ts, apps/meteor/app/api/server/v1/teams.ts
Updated routes to call eraseRoom(..., this.user) instead of this.userId.
Status & Presence
apps/meteor/app/lib/server/functions/setStatusText.ts, apps/meteor/app/lib/server/functions/saveUser/saveUser.ts, apps/meteor/app/user-status/server/methods/setUserStatus.ts, apps/meteor/app/slashcommands-status/server/status.ts, apps/meteor/app/lib/server/methods/saveSetting.ts
setStatusText signature changed to accept a user object (Pick<IUser,...>) and removed internal lookup; setUserStatusMethod updated to accept user:IUser; call sites updated; saveSetting tightened editor typing.
Threads & Chat Methods
apps/meteor/app/threads/server/methods/followMessage.ts, apps/meteor/app/threads/server/methods/unfollowMessage.ts, apps/meteor/app/api/server/v1/chat.ts
followMessage/unfollowMessage now accept user:IUser (use user._id internally); API routes pass this.user; Apps event triggers now receive provided user.
User Profile, Tokens & Search
apps/meteor/server/methods/saveUserProfile.ts, apps/meteor/app/api/server/v1/users.ts, apps/meteor/server/lib/removeOtherTokens.ts (removed), apps/meteor/server/methods/messageSearch.ts
saveUserProfile uses AuthenticatedContext and adds user existence guard; token invalidation switched to Users.removeNonLoginTokensExcept(this.userId, this.token); removeOtherTokens deleted; messageSearch fetches user via Users.findOneById.
Personal Access Tokens
apps/meteor/imports/personal-access-tokens/server/api/methods/*.ts
Added/expanded explicit type annotations for destructured parameters in generate/regenerate/remove token method handlers; no runtime behavior changes.
Events, REST & Misc
apps/meteor/app/message-pin/server/pinMessage.ts, apps/meteor/ee/server/apps/communication/rest.ts, apps/meteor/ee/server/api/roles.ts
Pass local me/this.user instead of Meteor.userAsync()/Meteor.userId() in Apps event payloads and REST handlers; roles.create reads userId from this.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Wrapper as twoFactorRequired wrapper
  participant TwoFactorSvc as checkCodeForUser
  participant Target as original method

  Client->>Wrapper: call method(args..., maybeTwoFactor)
  Wrapper->>Wrapper: pop last arg, inspect twoFactorCode/method
  alt twoFactor provided and validated
    Wrapper->>Wrapper: set twoFactorChecked, re-push args
  else not provided or not validated
    Wrapper->>TwoFactorSvc: checkCodeForUser(user, options)
    TwoFactorSvc-->>Wrapper: validated or throw
    Wrapper->>Wrapper: set twoFactorChecked, re-push args
  end
  Wrapper->>Target: fn.apply(this, args)
  Target-->>Client: result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • sampaiodiego
  • aleksandernsilva
  • cardoso

Poem

🐰 I hopped through code with careful paws,

Swapped IDs for users, updated the laws.
Two-factor checks now stand in line,
Context restored, the flows align.
A rabbit cheers — the changes are fine! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: replacing user IDs (strings) with full user objects as function parameters across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/stop-using-ids-for-functions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ggazzo ggazzo changed the base branch from develop to refactor/rate-limit-functions January 27, 2026 12:55
@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 57.14286% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.76%. Comparing base (c4eff65) to head (7bda6f6).
⚠️ Report is 6 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38367      +/-   ##
===========================================
- Coverage    70.80%   70.76%   -0.04%     
===========================================
  Files         3159     3158       -1     
  Lines       109364   109394      +30     
  Branches     19680    19649      -31     
===========================================
- Hits         77432    77416      -16     
- Misses       29897    29948      +51     
+ Partials      2035     2030       -5     
Flag Coverage Δ
unit 71.95% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

📦 Docker Image Size Report

➡️ Changes

Service Current Baseline Change Percent
sum of all images 0B 0B 0B
account-service 0B 0B 0B
authorization-service 0B 0B 0B
ddp-streamer-service 0B 0B 0B
omnichannel-transcript-service 0B 0B 0B
presence-service 0B 0B 0B
queue-worker-service 0B 0B 0B
rocketchat 0B 0B 0B

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 21:56", "12/08 20:15", "12/09 22:17", "12/10 23:26", "12/11 21:56", "12/12 22:45", "12/13 01:34", "12/15 22:31", "12/16 22:18", "12/17 21:04", "12/18 23:12", "12/19 23:27", "12/20 21:03", "12/22 18:54", "12/23 16:16", "12/24 19:38", "12/25 17:51", "12/26 13:18", "12/29 19:01", "12/30 20:52", "01/28 12:46 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.00]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "queue-worker-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "rocketchat" [0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.00]
Loading

Statistics (last 30 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.4GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 0B
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-38367
  • Baseline: develop
  • Timestamp: 2026-01-28 12:46:13 UTC
  • Historical data points: 30

Updated: Wed, 28 Jan 2026 12:46:13 GMT

Base automatically changed from refactor/rate-limit-functions to develop January 27, 2026 13:23
…rectly from Users model for improved accuracy
…cept user object instead of userId for improved clarity
@ggazzo ggazzo force-pushed the chore/stop-using-ids-for-functions branch from 34c7bda to c0f1958 Compare January 27, 2026 13:24
@ggazzo ggazzo marked this pull request as ready for review January 27, 2026 13:25
@ggazzo ggazzo requested a review from a team as a code owner January 27, 2026 13:25
@ggazzo ggazzo added this to the 8.2.0 milestone Jan 27, 2026
@ggazzo ggazzo changed the title chore: replace ids and objects chore: replace ids with objects as parameters Jan 27, 2026
@ggazzo ggazzo force-pushed the chore/stop-using-ids-for-functions branch from c0f1958 to 671e348 Compare January 27, 2026 13:30
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/meteor/ee/server/apps/communication/rest.ts (1)

913-918: Guard convertToApp in the delete route to avoid a runtime throw.

Other routes use optional chaining when resolving the users converter, but this path will throw if the converter is unavailable.

🛠️ Suggested fix
-					const user = orchestrator?.getConverters()?.get('users').convertToApp(this.user);
+					const user = orchestrator?.getConverters()?.get('users')?.convertToApp(this.user);
🤖 Fix all issues with AI agents
In `@apps/meteor/app/lib/server/functions/saveUser/saveUser.ts`:
- Around line 127-129: The call to setStatusText currently unsafely casts
userData to IUser; instead pass the full existing user document oldUserData
(which contains required fields like createdAt, roles, type, active, _updatedAt)
as the user argument and keep userData.statusText as the new status string;
update the call from setStatusText(userData as IUser, userData.statusText, {
updater, session }) to setStatusText(oldUserData, userData.statusText, {
updater, session }) so setStatusText receives a complete IUser for presence
broadcast while using the incoming SaveUserData.statusText as the new value.

In `@apps/meteor/app/message-pin/server/pinMessage.ts`:
- Line 112: In pinMessage, the Apps.self?.triggerEvent call passes an undefined
variable user; replace that argument with the existing me object (the
authenticated user retrieved earlier in pinMessage) so the event uses the
correct user object (update the AppEvents.IPostMessagePinned invocation to pass
me instead of user and scan pinMessage for any other references to user that
should be me).
- Line 192: The unpinMessage function calls
Apps.self?.triggerEvent(AppEvents.IPostMessagePinned, originalMessage, user,
originalMessage.pinned) but the variable is named me in this scope; update the
call in unpinMessage to pass the correct user object (me) instead of undefined
user—i.e., replace user with me (or assign const user = me earlier) so
Apps.self?.triggerEvent and any related code use the defined user variable.

In `@apps/meteor/app/slashcommands-status/server/status.ts`:
- Around line 17-24: The Users.findOneById call uses a too-narrow projection
(only language) but setUserStatusMethod ultimately calls setStatusText which
expects user.statusText, user.username, user.status, user.name, and user.roles;
update the projection used in Users.findOneById to include these fields so the
user object passed to setUserStatusMethod/setStatusText has statusText,
username, status, name, roles (in addition to language/_id).
🧹 Nitpick comments (1)
apps/meteor/server/methods/messageSearch.ts (1)

72-74: Consider using userId directly instead of user?._id.

Since userId is already available as a parameter and should equal user._id when the user exists, this could be simplified. Using userId directly would also maintain search functionality if the user document is somehow missing but the userId is valid.

♻️ Suggested simplification
 	} else {
 		query.rid = {
-			$in: user?._id ? (await Subscriptions.findByUserId(user._id).toArray()).map((subscription: ISubscription) => subscription.rid) : [],
+			$in: (await Subscriptions.findByUserId(userId).toArray()).map((subscription: ISubscription) => subscription.rid),
 		};
 	}

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 30 files

@ggazzo ggazzo force-pushed the chore/stop-using-ids-for-functions branch from 671e348 to d531c0e Compare January 27, 2026 13:47
@ggazzo ggazzo requested a review from Copilot January 27, 2026 13:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors several server methods and REST endpoints to pass full objects (e.g., IUser) instead of IDs, improving type safety and reducing repeated lookups.

Changes:

  • Updated multiple method signatures to accept IUser objects (threads follow/unfollow, status, erase-room/team flows).
  • Simplified token invalidation by removing removeOtherTokens helper and calling Users.removeNonLoginTokensExcept directly.
  • Tightened typings in 2FA wrappers and personal access token methods; updated affected tests.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
apps/meteor/server/methods/saveUserProfile.ts Switches to object-based status updates and updates token invalidation logic.
apps/meteor/server/methods/messageSearch.ts Uses model lookup for user context instead of Meteor.userAsync().
apps/meteor/server/lib/removeOtherTokens.ts Removes helper in favor of direct model call.
apps/meteor/server/lib/eraseRoom.ts Changes API to accept IUser and removes internal Meteor.userAsync() lookup.
apps/meteor/imports/personal-access-tokens/server/api/methods/removeToken.ts Adds explicit param typing / minor refactor.
apps/meteor/imports/personal-access-tokens/server/api/methods/regenerateToken.ts Adds explicit param typing.
apps/meteor/imports/personal-access-tokens/server/api/methods/generateToken.ts Formats/clarifies function signature and method params typing.
apps/meteor/ee/server/apps/communication/rest.ts Uses this.user for app management actions instead of Meteor.userAsync().
apps/meteor/ee/server/api/roles.ts Uses request context this.userId instead of Meteor.userId().
apps/meteor/app/user-status/server/methods/setUserStatus.ts Refactors status method to accept IUser and routes through setStatusText(user, ...).
apps/meteor/app/threads/server/methods/unfollowMessage.ts Refactors to accept IUser and reuses it for app event trigger.
apps/meteor/app/threads/server/methods/followMessage.ts Refactors to accept IUser and reuses it for app event trigger.
apps/meteor/app/slashcommands-status/server/status.ts Updates slash command to call setUserStatusMethod(user, ...).
apps/meteor/app/message-pin/server/pinMessage.ts Uses already-fetched me for app event trigger instead of Meteor.userAsync().
apps/meteor/app/lib/server/methods/saveSetting.ts Tightens editor parameter typing to SettingEditor.
apps/meteor/app/lib/server/functions/setStatusText.ts Refactors to accept a user object instead of fetching by ID.
apps/meteor/app/lib/server/functions/saveUser/saveUser.ts Updates statusText path to call setStatusText(user, ...).
apps/meteor/app/api/server/v1/users.ts Updates REST endpoints to match new signatures and direct token invalidation.
apps/meteor/app/api/server/v1/teams.ts Updates erase-room calls to pass this.user.
apps/meteor/app/api/server/v1/rooms.ts Updates erase-room calls to pass this.user.
apps/meteor/app/api/server/v1/im.ts Updates erase-room calls to pass this.user.
apps/meteor/app/api/server/v1/groups.ts Updates erase-room calls to pass this.user.
apps/meteor/app/api/server/v1/chat.ts Updates follow/unfollow calls to pass this.user.
apps/meteor/app/api/server/v1/channels.ts Updates erase-room calls to pass this.user.
apps/meteor/app/api/server/lib/eraseTeam.ts Updates erase team helpers to pass user objects through to eraseRoom.
apps/meteor/app/api/server/lib/eraseTeam.spec.ts Updates test expectations for new eraseRoom signature.
apps/meteor/app/api/server/helpers/getUserFromParams.ts Simplifies params type annotation / inferred return type.
apps/meteor/app/2fa/server/twoFactorRequired.ts Refactors wrapper typing for broader this compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

?.getConverters()
?.get('users')
.convertToApp(await Meteor.userAsync());
const user = orchestrator?.getConverters()?.get('users').convertToApp(this.user);
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

This line drops the optional chaining on get('users'). If the converter is missing, orchestrator?.getConverters()?.get('users') can be undefined, and calling .convertToApp(...) will throw.

Keep the ?. before .convertToApp here for consistency with the other occurrences in this file (e.g., around line 877).

Suggested change
const user = orchestrator?.getConverters()?.get('users').convertToApp(this.user);
const user = orchestrator?.getConverters()?.get('users')?.convertToApp(this.user);

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/meteor/app/api/server/helpers/getUserFromParams.ts`:
- Around line 6-7: The function getUserFromParams is missing an explicit return
type and uses an untyped let user;—add a proper return type annotation (e.g.,
the same Promise<User | null> or the exact union used by getUserListFromParams)
to the function signature and type the internal user variable accordingly so
callers can statically access ._id and .username; mirror the return type/pattern
from getUserListFromParams and update getUserFromParams's signature and user
declaration to match.
🧹 Nitpick comments (1)
apps/meteor/app/2fa/server/twoFactorRequired.ts (1)

12-12: Consider adding explicit this type annotation.

The inner async function has an implicit this: any which relies on the final type assertion (line 40) for correctness. While this works, adding an explicit type annotation would make the intent clearer and catch potential issues earlier.

♻️ Optional improvement
-	async function (this, ...args) {
+	async function (this: Meteor.MethodThisType & { twoFactorChecked?: boolean }, ...args) {

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 28 files

@ggazzo ggazzo force-pushed the chore/stop-using-ids-for-functions branch from e1eadc0 to 79b20d2 Compare January 28, 2026 12:33
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@apps/meteor/app/2fa/server/twoFactorRequired.ts`:
- Line 6: The AuthenticatedContext type declares connection as required but the
wrapper and checkCodeForUser treat it as optional; change the
AuthenticatedContext definition (AuthenticatedContext) to make connection
optional (connection?: Meteor.Connection) so it matches checkCodeForUser's
signature and removes the need for defensive this.connection || undefined usage
in the wrapper functions that call checkCodeForUser.
- Around line 8-15: The exported twoFactorRequired wrapper incorrectly exposes a
non-Promise return type because the wrapper is async; update its generic
signature so the returned function type reflects a Promise by either
constraining TFunction to async functions (e.g. TFunction extends (...args:any)
=> Promise<any>) or change the asserted return type to
Promise<Awaited<ReturnType<TFunction>>>; adjust the cast on the returned async
function accordingly and keep the existing type checks involving
ThisParameterType<TFunction>, ReturnType<TFunction>, and ITwoFactorOptions in
sync with the new Promise-wrapped return type.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/meteor/app/2fa/server/twoFactorRequired.ts (1)

23-43: Don’t drop falsy last arguments when probing for two‑factor options.

args.pop() + if (twoFactor) loses valid falsy values (e.g., false, 0, '', null) and changes the wrapped function’s behavior. Preserve any non‑two‑factor value.

🛠️ Suggested fix
-		const twoFactor = args.pop();
-		if (twoFactor) {
-			if (twoFactor.twoFactorCode && twoFactor.twoFactorMethod) {
+		const twoFactor = args.pop();
+		if (twoFactor && twoFactor.twoFactorCode && twoFactor.twoFactorMethod) {
 				await checkCodeForUser({
 					user: this.userId,
 					connection: this.connection || undefined,
 					code: twoFactor.twoFactorCode,
 					method: twoFactor.twoFactorMethod,
 					options,
 				});
 				this.twoFactorChecked = true;
-			} else {
-				// if it was not two factor options, put it back
-				args.push(twoFactor);
-			}
+		} else if (twoFactor !== undefined) {
+			args.push(twoFactor);
 		}

@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Jan 28, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Jan 28, 2026
@ggazzo ggazzo merged commit f4d7cc7 into develop Jan 28, 2026
21 of 22 checks passed
@ggazzo ggazzo deleted the chore/stop-using-ids-for-functions branch January 28, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants