RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-user
error-invalid-user
Error message
The optional "userId" param provided does not match any users
What it means
Thrown by users.setPreferences after the edit-other-user check passes: Users.findOneById(userId) returns nothing, so the resolved target user does not exist.
Source
Thrown at apps/meteor/server/api/v1/users.ts:247
authRequired: true,
body: isUsersSetPreferencesParamsPOST,
response: {
200: userObjectResponse,
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
},
},
async function action() {
if (
this.bodyParams.userId &&
this.bodyParams.userId !== this.userId &&
!(await hasPermissionAsync(this.user, 'edit-other-user-info'))
) {
throw new Meteor.Error('error-action-not-allowed', 'Editing user is not allowed');
}
const userId = this.bodyParams.userId ? this.bodyParams.userId : this.userId;
if (!(await Users.findOneById(userId))) {
throw new Meteor.Error('error-invalid-user', 'The optional "userId" param provided does not match any users');
}
await saveUserPreferences(this.bodyParams.data, userId);
const user = await Users.findOneById(userId, {
projection: {
'settings.preferences': 1,
'language': 1,
},
});
if (!user) {
return API.v1.failure('User not found');
}
return API.v1.success({
user: {
_id: user._id,
settings: {View on GitHub (pinned to f9d3ec372b)
Solutions
- Send a valid userId that exists in this workspace, or omit it to target yourself.
- Refresh the client's cached userId from /api/v1/me before calling.
- Verify the user exists via users.info before editing preferences.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
// Confirm target exists before editing preferences
if (targetUserId) {
const u = await GET(`users.info?userId=${encodeURIComponent(targetUserId)}`);
if (!u?.user) return;
} Type guard
null
Try / catch
try {
await POST('users.setPreferences', body);
} catch (e) {
if (isMeteorError(e, 'error-invalid-user')) {
// refresh client user list; the cached userId is stale
} else { throw e; }
} Prevention
- Resolve the current userId from /api/v1/me rather than caching indefinitely.
- Validate userIds against users.info in admin UIs before edits.
When it happens
Trigger: POST users.setPreferences with a userId (own or via edit-other-user-info) that does not match any user document.
Common situations: Stale userId in client state after account deletion; typo in userId; referencing a user from another workspace.
Related errors
- error-invalid-query
- error-invalid-date
- Invalid Api parameter provided, it must be a valid IApi obje
- Creating normal users is currently not supported
- User not provided
AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12).
Data as JSON: /api/errors/5bf8135809165cb4.
Report an issue: GitHub.