{"record":{"id":"1f2cd73f6272996a","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-1f2cd7","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"error_code","errorClass":"MeteorError","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/lib/omnichannel/LivechatEnterprise.ts","lineNumber":21,"sourceCode":"import { Users, OmnichannelServiceLevelAgreements, LivechatTag, LivechatUnitMonitors, LivechatUnit } from '@rocket.chat/models';\nimport { getUnitsFromUser } from '@rocket.chat/omni-core-ee';\nimport { Match, check } from 'meteor/check';\nimport { Meteor } from 'meteor/meteor';\n\nimport { updateSLAInquiries } from './Helper';\nimport { removeSLAFromRooms } from './SlaHelper';\nimport { callbacks } from '../../../../server/lib/callbacks';\nimport { addUserRolesAsync } from '../../../../server/lib/roles/addUserRoles';\nimport { removeUserFromRolesAsync } from '../../../../server/lib/roles/removeUserFromRoles';\n\nexport const LivechatEnterprise = {\n\tasync addMonitor(username: string) {\n\t\tconst user = await Users.findOneByUsername<Pick<IUser, '_id' | 'username' | 'roles'>>(username, {\n\t\t\tprojection: { _id: 1, username: 1, roles: 1 },\n\t\t});\n\n\t\tif (!user) {\n\t\t\tthrow new MeteorError('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'livechat:addMonitor',\n\t\t\t});\n\t\t}\n\n\t\tif (!(await addUserRolesAsync(user._id, ['livechat-monitor']))) {\n\t\t\tthrow new MeteorError('error-adding-monitor-role', 'Error adding monitor role', {\n\t\t\t\tmethod: 'livechat:addMonitor',\n\t\t\t});\n\t\t}\n\n\t\treturn user;\n\t},\n\n\tasync removeMonitor(username: string) {\n\t\tconst user = await Users.findOneByUsername<Pick<IUser, '_id'>>(username, {\n\t\t\tprojection: { _id: 1 },\n\t\t});\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/lib/omnichannel/LivechatEnterprise.ts#L3-L39","documentation":"LivechatEnterprise.addMonitor looks up the given username in the Users collection to promote that user to livechat-monitor. If no user matches, it throws Meteor error error-invalid-user with method livechat:addMonitor.","triggerScenarios":"Calling livechat:addMonitor (Meteor method or REST /api/v1/livechat/monitors.add) with a username that does not exist, is misspelled, or differs in casing/whitespace.","commonSituations":"Frontend sending a stale username after the user was renamed or deleted; scripts referencing removed accounts; copy-paste with trailing spaces.","solutions":["Verify the exact username first: GET /api/v1/users.info?username=<name>","Copy the username from the user's profile to avoid casing/whitespace mistakes","Create the user account before trying to make it a monitor"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const user = await Users.findOneByUsername(username, { projection: { _id: 1, roles: 1 } });\nif (!user) {\n\t// reject early with a clear 'username not found' message\n}\nawait LivechatEnterprise.addMonitor(username);","typeGuard":null,"tryCatchPattern":"try {\n\tawait LivechatEnterprise.addMonitor(username);\n} catch (err) {\n\tif ((err as Meteor.Error)?.error === 'error-invalid-user') {\n\t\t// show 'user not found' for the supplied username\n\t} else {\n\t\tthrow err;\n\t}\n}","preventionTips":["Use autocomplete on existing usernames instead of free-text entry","Trim whitespace and match exact casing when passing usernames","Re-validate usernames when renaming users anywhere in the workspace"],"tags":["omnichannel","monitor","user-lookup"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}