{"record":{"id":"f9f2faeec2f2d809","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-f9f2fa","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/createChannel.ts","lineNumber":36,"sourceCode":"\t\t\tcustomFields?: Record<string, any>,\n\t\t\textraData?: Record<string, any>,\n\t\t): ICreatedRoom;\n\t}\n}\n\nexport const createChannelMethod = async (\n\tuserId: string,\n\tname: string,\n\tmembers: string[],\n\treadOnly = false,\n\tcustomFields?: Record<string, any>,\n\textraData: Record<string, any> = {},\n\texcludeSelf = false,\n) => {\n\tcheck(name, String);\n\tcheck(members, Match.Optional([String]));\n\tif (!userId) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'createChannel' });\n\t}\n\n\tconst user = await Users.findOneById(userId, { projection: { services: 0 } });\n\tif (!user?.username) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'createChannel' });\n\t}\n\n\tif (extraData.teamId) {\n\t\tconst team = await Team.findOneById<Pick<ITeam, '_id' | 'roomId'>>(extraData.teamId, { projection: { roomId: 1 } });\n\t\tif (!team) {\n\t\t\tthrow new Meteor.Error('error-team-not-found', 'The \"teamId\" param provided does not match any team', { method: 'createChannel' });\n\t\t}\n\t\tif (!(await hasPermissionAsync(userId, 'create-team-channel', team.roomId))) {\n\t\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'createChannel' });\n\t\t}\n\t} else if (!(await hasPermissionAsync(userId, 'create-c'))) {\n\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'createChannel' });\n\t}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/createChannel.ts#L18-L54","documentation":"First guard in the exported createChannelMethod helper: the userId argument itself is falsy. The createChannel DDP wrapper resolves and checks Meteor.userId() on its own, so this specific throw is for internal/server-side callers that passed undefined/null/'' as the user id.","triggerScenarios":"Custom server code imports createChannelMethod and passes a uid variable that is undefined (Meteor.userId() read outside a request, wrong destructuring, or an argument-order mistake in the long positional signature name/members/readOnly/customFields/extraData/excludeSelf).","commonSituations":"Logic ported into workers/jobs where no user context exists; refactors that drop or shift arguments; code copied from the wrapper with uid forgotten.","solutions":["Pass an explicit, existing user _id as the first argument.","Capture Meteor.userId() inside the request context and propagate it into async continuations that call the helper.","Where no human actor exists, use a designated admin/system account or call the createRoom service directly."],"exampleFix":"// before\ncreateChannelMethod(Meteor.userId(), name, members); // null outside a request\n\n// after\nconst uid = Meteor.userId();\nif (!uid) {\n  throw new Error('createChannelMethod requires a user id');\n}\ncreateChannelMethod(uid, name, members);","handlingStrategy":"validation","validationCode":"if (!uid) {\n  throw new Error('createChannelMethod requires a real user id');\n}\nawait createChannelMethod(uid, name, members);","typeGuard":"const isNonEmptyUserId = (uid: string | null | undefined): uid is string =>\n  typeof uid === 'string' && uid.length > 0;","tryCatchPattern":"try {\n  await createChannelMethod(uid, name, members);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    // internal caller bug: uid was falsy - fix the call site, do not retry\n    throw new Error('createChannelMethod called without a user id');\n  }\n  throw e;\n}","preventionTips":["Pass the uid explicitly when reusing createChannelMethod outside the DDP wrapper.","Capture Meteor.userId() inside the request and propagate it into async continuations (Meteor.bindEnvironment) instead of reading it later.","Give the helper's arguments explicit types so a missing uid fails at compile time."],"tags":["rocket-chat","meteor","create-channel","user-validation","server-side"],"backgroundTag":"meteor-invalid-user","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}