{"record":{"id":"83b9721eee40bf26","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-83b972","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/e2e/functions/handleSuggestedGroupKey.ts","lineNumber":13,"sourceCode":"import { Rooms, Subscriptions } from '@rocket.chat/models';\nimport { Meteor } from 'meteor/meteor';\n\nimport { notifyOnSubscriptionChangedById, notifyOnRoomChangedById } from '../../notifyListener';\n\nexport async function handleSuggestedGroupKey(\n\thandle: 'accept' | 'reject',\n\trid: string,\n\tuserId: string | null,\n\tmethod: string,\n): Promise<void> {\n\tif (!userId) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method });\n\t}\n\n\tconst sub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId);\n\tif (!sub) {\n\t\tthrow new Meteor.Error('error-subscription-not-found', 'Subscription not found', { method });\n\t}\n\n\tconst suggestedKey = String(sub.E2ESuggestedKey ?? '').trim();\n\tif (!suggestedKey) {\n\t\tthrow new Meteor.Error('error-no-suggested-key-available', 'No suggested key available', { method });\n\t}\n\n\tif (handle === 'accept') {\n\t\t// A merging process can happen here, but we're not doing that for now\n\t\t// If a user already has oldRoomKeys, we will ignore the suggested ones\n\t\tconst oldKeys = sub.oldRoomKeys ? undefined : sub.suggestedOldRoomKeys;\n\t\tawait Subscriptions.setGroupE2EKeyAndOldRoomKeys(sub._id, suggestedKey, oldKeys);\n\t\tconst { modifiedCount } = await Rooms.removeUsersFromE2EEQueueByRoomId(sub.rid, [userId]);","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/e2e/functions/handleSuggestedGroupKey.ts#L1-L31","documentation":"The E2E suggested-group-key handler (accept/reject) requires an acting user, and it throws this Meteor.Error when the userId argument is null — i.e. there is no authenticated user in the method invocation context. Without a user there is no subscription to look up, so the operation cannot proceed.","triggerScenarios":"The Meteor method delegating to handleSuggestedGroupKey runs with this.userId null — unauthenticated client invocation, or server-side code calling the handler without passing a user id.","commonSituations":"Expired login token on a client that still fires the EEE key dialog action; custom code invoking the method via Meteor.call without a user context; refactors that dropped the userId argument.","solutions":["Make the call from an authenticated session so this.userId is populated","If invoking the handler from server code, pass an explicit, existing userId instead of null"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const userId = Meteor.userId() /* or this.userId in a method */;\nif (!userId) {\n  // require login before showing/invoking the suggested-key action\n}","typeGuard":"const isUserId = (userId: string | null | undefined): userId is string =>\n  typeof userId === 'string' && userId.trim().length > 0;","tryCatchPattern":null,"preventionTips":["Guard Meteor method wrappers with a this.userId check before delegating to E2E handlers","Never fire E2E key actions from code paths that can run unauthenticated"],"tags":["e2e","authentication","meteor-methods"],"backgroundTag":"authentication-required","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}