{"record":{"id":"5388910481ab5a1d","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-538891","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/rooms/addUsersToRoom.ts","lineNumber":32,"sourceCode":"declare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\taddUsersToRoom(data: { rid: string; users: string[] }): boolean;\n\t}\n}\n\nexport const sanitizeUsername = (username: string) => {\n\tconst isFederatedUsername = username.includes('@') && username.includes(':');\n\tif (isFederatedUsername) {\n\t\treturn username;\n\t}\n\n\treturn username.replace(/(^@)|( @)/, '');\n};\n\nexport const addUsersToRoomMethod = async (userId: string, data: { rid: string; users: string[] }, user?: IUser): Promise<boolean> => {\n\tif (!userId) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tmethod: 'addUsersToRoom',\n\t\t});\n\t}\n\n\tif (!Match.test(data.rid, String)) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', {\n\t\t\tmethod: 'addUsersToRoom',\n\t\t});\n\t}\n\n\t// Get user and room details\n\tconst room = await Rooms.findOneById(data.rid);\n\tif (!room) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', {\n\t\t\tmethod: 'addUsersToRoom',\n\t\t});\n\t}\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/addUsersToRoom.ts#L14-L50","documentation":"Thrown by the exported addUsersToRoomMethod() in apps/meteor/server/meteor-methods/rooms/addUsersToRoom.ts:32 when the userId argument is falsy. Unlike the Meteor method wrappers, this helper takes the acting user ID as a parameter, so callers must supply it; the guard is a plain truthiness check before the rid validation runs.","triggerScenarios":"Calling addUsersToRoomMethod('', rid, users) or with undefined/null userId — e.g. a caller that did Meteor.userId() ?? '' , a server job that lost its user context, or code passing the user object instead of its _id (object._id of a malformed object).","commonSituations":"Server-side automation invoking the helper outside a request context; refactors where the first parameter was changed from an IUser to a userId string and callers were not all updated; default-parameter code paths that pass undefined.","solutions":["Pass a real acting user ID: resolve it via Meteor.userId() in method contexts or accept it explicitly in jobs.","Validate before calling: if (!userId) fail fast with your own error naming the missing parameter.","Prefer the public REST endpoints POST /v1/channels.invite / POST /v1/groups.invite for integrations, which authenticate via headers.","If you own the call site, make the parameter required in TypeScript (userId: string, not userId?: string) so the compiler catches omissions."],"exampleFix":"// before\nawait addUsersToRoomMethod(Meteor.userId(), { rid, users });\n\n// after\nconst uid = Meteor.userId();\nif (!uid) throw new Error('no acting user; authenticate first');\nawait addUsersToRoomMethod(uid, { rid, users });","handlingStrategy":"validation","validationCode":"const uid = Meteor.userId();\nif (!uid) throw new Error('no acting user; authenticate first');\nawait addUsersToRoomMethod(uid, { rid, users });","typeGuard":"const isNonEmptyString = (v: unknown): v is string => typeof v === 'string' && v.length > 0;","tryCatchPattern":"try {\n  await addUsersToRoomMethod(userId, data);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    // caller passed a falsy userId: fix the call site, do not retry\n  }\n}","preventionTips":["Type the parameter as required string in your own wrappers so TS rejects omissions.","Resolve the acting user from the session at call time.","Fail fast at entry points when no user context is bound."],"tags":["meteor-method","validation","users","rooms"],"backgroundTag":"missing-acting-user-id","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}