{"record":{"id":"9a73e4815d6ca82f","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-9a73e4","errorCode":"error-invalid-user","errorMessage":"error-invalid-user","messagePattern":"error-invalid-user","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/v1/omnichannel/transcript.ts","lineNumber":65,"sourceCode":"\n\t\t\tif (!(await Omnichannel.isWithinMACLimit(room))) {\n\t\t\t\tthrow new Error('error-mac-limit-reached');\n\t\t\t}\n\n\t\t\tawait LivechatRooms.unsetEmailTranscriptRequestedByRoomId(rid);\n\n\t\t\treturn API.v1.success();\n\t\t},\n\t\tasync post() {\n\t\t\tconst { rid } = this.urlParams;\n\t\t\tconst { email, subject } = this.bodyParams;\n\n\t\t\tconst user = await Users.findOneById(this.userId, {\n\t\t\t\tprojection: { _id: 1, username: 1, name: 1, utcOffset: 1 },\n\t\t\t});\n\n\t\t\tif (!user) {\n\t\t\t\tthrow new Error('error-invalid-user');\n\t\t\t}\n\n\t\t\tawait requestTranscript({ rid, email, subject, user });\n\n\t\t\treturn API.v1.success();\n\t\t},\n\t},\n);\n","sourceCodeStart":47,"sourceCodeEnd":74,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/omnichannel/transcript.ts#L47-L74","documentation":"Thrown in the POST livechat/room/:rid/transcript handler after fetching the authenticated user with Users.findOneById(this.userId) and getting null. Because authRequired is on, this.userId is populated by the framework, so a null user record means the authenticated token points at a user that no longer exists in the database.","triggerScenarios":"A request carries a valid auth token (X-Auth-Token + X-User-Id) for a userId whose document was deleted or whose collection is inconsistent. requestTranscript would NPE on the null user, so the guard fails fast instead.","commonSituations":"User was deleted between token issuance and this call; a stale token cached in a client after admin deletion; test fixtures that authenticate but never insert the user; database restored from a backup that is missing the users collection.","solutions":["Verify the X-User-Id header matches an existing user document in the users collection.","If the user was deleted intentionally, invalidate the client's stored auth token (logout) before retrying.","Check for fixture/seed inconsistencies in non-production environments.","Audit logs for user deletion events around the time of the failure."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"const me = await fetch('/api/v1/v1/me', { headers: authHeaders });\nif (!me.ok) { /* session invalid - re-login before calling transcript */ }","typeGuard":"null","tryCatchPattern":"try {\n  await requestTranscript({ rid, email, subject, user });\n} catch (e) {\n  if (e.error === 'error-invalid-user') { /* clear local session, re-authenticate */ }\n  else throw e;\n}","preventionTips":["Validate the session with a lightweight /me call before user-dependent operations.","Clear cached tokens on 401/invalid-user responses.","Do not persist auth tokens longer than the user lifetime."],"tags":["authentication","user","transcript","stale-token"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}