{"record":{"id":"18b18e2f32237191","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-18b18e","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/addUserToRoom.ts","lineNumber":19,"sourceCode":"import type { ServerMethods } from '@rocket.chat/ddp-client';\nimport { Meteor } from 'meteor/meteor';\n\nimport { addUsersToRoomMethod } from './addUsersToRoom';\nimport { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\taddUserToRoom(data: { rid: string; username: string }): void;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync addUserToRoom(data) {\n\t\tmethodDeprecationLogger.method('addUserToRoom', '9.0.0', ['/v1/channels.invite', '/v1/groups.invite']);\n\t\tconst userId = Meteor.userId();\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'addUserToRoom',\n\t\t\t});\n\t\t}\n\n\t\tawait addUsersToRoomMethod(userId, {\n\t\t\trid: data.rid,\n\t\t\tusers: [data.username],\n\t\t});\n\t},\n});\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/addUserToRoom.ts#L1-L30","documentation":"Thrown by the 'addUserToRoom' Meteor method (apps/meteor/server/meteor-methods/rooms/addUserToRoom.ts:19) when Meteor.userId() is falsy — the invoking DDP connection has no authenticated user. After the gate it immediately delegates to addUsersToRoomMethod with a single-element users array, so this is purely an authentication failure, not a room/user validation one. The method is deprecated as of 9.0.0 in favor of POST /v1/channels.invite and /v1/groups.invite.","triggerScenarios":"Meteor.call('addUserToRoom', { rid, username }) from an unauthenticated or logged-out connection; expired login token; DDP integration that skipped the login handshake; calling the method from server code where no user context is bound.","commonSituations":"Sessions cleared after password resets or logout on another tab; scripts using DDP without credentials; front-end calling before login finishes; bots connecting with an invalid token that silently leaves userId unset.","solutions":["Authenticate the connection first and verify with Meteor.userId() before invoking.","Re-login when the token has expired, then retry.","Move to the REST invite endpoints (POST /v1/channels.invite, POST /v1/groups.invite) which take explicit auth headers and are the supported path.","For tests, use a logged-in user fixture connection (e.g. meteor-factory/test login) rather than an anonymous one."],"exampleFix":"// before\nMeteor.call('addUserToRoom', { rid, username });\n\n// after\nif (!Meteor.userId()) throw new Error('login required');\nMeteor.call('addUserToRoom', { rid, username });","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) throw new Error('login required');\nMeteor.call('addUserToRoom', { rid, username });","typeGuard":"const isLoggedIn = (): boolean => Boolean(Meteor.userId());","tryCatchPattern":"try {\n  Meteor.call('addUserToRoom', { rid, username });\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    // session missing/expired: re-login then retry\n  }\n}","preventionTips":["Authenticate DDP connections before any method call.","Migrate to REST invite endpoints (/v1/channels.invite, /v1/groups.invite).","Gate invite UI on authenticated state."],"tags":["meteor-method","authentication","ddp","rooms","deprecated"],"backgroundTag":"meteor-user-not-logged-in","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}