{"record":{"id":"ef12447af4040e54","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-ef1244","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/slashcommands/unarchiveroom/server.ts","lineNumber":32,"sourceCode":"\nslashCommands.add({\n\tcommand: 'unarchive',\n\tcallback: async function Unarchive({ params, message, userId }: SlashCommandCallbackParams<'unarchive'>): Promise<void> {\n\t\tlet channel = params.trim();\n\t\tlet room;\n\n\t\tif (channel === '') {\n\t\t\troom = await Rooms.findOneById(message.rid);\n\t\t\tif (room?.name) {\n\t\t\t\tchannel = room.name;\n\t\t\t}\n\t\t} else {\n\t\t\tchannel = channel.replace('#', '');\n\t\t\troom = await Rooms.findOneByName(channel);\n\t\t}\n\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });\n\t\t}\n\n\t\tconst user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });\n\t\tif (!user || !isRegisterUser(user)) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });\n\t\t}\n\n\t\tif (!room) {\n\t\t\tvoid api.broadcast('notify.ephemeralMessage', userId, message.rid, {\n\t\t\t\tmsg: i18n.t('Channel_doesnt_exist', {\n\t\t\t\t\tchannelName: channel,\n\t\t\t\t\tlng: settings.get('Language') || 'en',\n\t\t\t\t}),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tif (!(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE, userId))) {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/slashcommands/unarchiveroom/server.ts#L14-L50","documentation":"First 'error-invalid-user' guard in the /unarchiveroom slash command: it fires when the command's context carries no userId at all (null/undefined). Note the method field says 'archiveRoom' — a copy-paste artifact — but the throw site is unarchiveroom. Without a userId the command cannot check the 'unarchive-room' permission or attribute the action, so it aborts.","triggerScenarios":"/unarchiveroom is invoked from a context where this.userId is absent: server-side invocation of the slash command with no authenticated user, a hook/bot calling executeSlashCommand without a userId, or an anonymous/offline connection reaching the method.","commonSituations":"Integrations or tests invoking slashCommands.execute programmatically and omitting the userId parameter; custom code triggering commands from system contexts.","solutions":["Ensure the command is run by a logged-in user (this.userId set) — type /unarchiveroom in an authenticated session.","When invoking programmatically, pass a real userId: executeSlashCommand(command, params, message, userId).","Check that the method binding that dispatches slash commands is not being called from a publish or non-user context."],"exampleFix":"// before\nif (!userId) {\n  throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });\n}\n\n// programmatic invocation fix\nimport { api } from 'meteor/rocketchat:api';\nawait api.executeSlashCommand('unarchiveroom', '#channel', { rid }, loggedInUserId);","handlingStrategy":"validation","validationCode":"const userId = Meteor.userId();\nif (!userId) {\n  // do not invoke /unarchiveroom from an anonymous/system context\n  throw new Error('Login required');\n}\nawait Meteor.callAsync('slashCommand', { command: 'unarchiveroom', params: `#${channel}`, rid: message.rid });","typeGuard":null,"tryCatchPattern":"try { await runUnarchive(); } catch (e) { if (isMeteorError(e, 'error-invalid-user')) { /* ensure an authenticated user context */ return; } throw e; }","preventionTips":["Only invoke slash commands from an authenticated user session.","Pass a real userId when calling executeSlashCommand programmatically.","Never trigger user-context commands from publish functions or system jobs."],"tags":["rocket-chat","slash-command","authentication","meteor"],"backgroundTag":"missing-authenticated-user","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}