{"record":{"id":"8ec2b976f55019f8","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-8ec2b9","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/platform/setRoomKeyID.ts","lineNumber":40,"sourceCode":"\tconst room = await Rooms.setE2eKeyId(rid, keyID);\n\n\tif (!room) {\n\t\tthrow new Meteor.Error('error-room-e2e-key-already-exists', 'E2E Key ID already exists', {\n\t\t\tmethod: 'e2e.setRoomKeyID',\n\t\t});\n\t}\n\n\tvoid notifyOnRoomChanged(room);\n};\n\nMeteor.methods<ServerMethods>({\n\tasync 'e2e.setRoomKeyID'(rid, keyID) {\n\t\tcheck(rid, String);\n\t\tcheck(keyID, String);\n\n\t\tconst userId = Meteor.userId();\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'e2e.setRoomKeyID' });\n\t\t}\n\n\t\tif (!rid) {\n\t\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'e2e.setRoomKeyID' });\n\t\t}\n\n\t\tawait setRoomKeyIDMethod(userId, rid, keyID);\n\t},\n});\n","sourceCodeStart":22,"sourceCodeEnd":50,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/platform/setRoomKeyID.ts#L22-L50","documentation":"The `e2e.setRoomKeyID` wrapper throws `error-invalid-user` when `Meteor.userId()` is null — submitting a room E2E key id requires an authenticated connection, since the key is attributed to and authorized against the logged-in user.","triggerScenarios":"Calling `Meteor.call('e2e.setRoomKeyID', rid, keyID)` while logged out — session expired during the E2E handshake or the flow started pre-login.","commonSituations":"E2E setup racing the login flow; retries after logout.","solutions":["Log in before starting the E2E key exchange","Check `Meteor.userId()` first and route to login when absent","Re-run the key exchange after re-authenticating"],"exampleFix":"// before\nMeteor.call('e2e.setRoomKeyID', rid, keyID);\n// after\nif (!Meteor.userId()) {\n  return handleSessionExpired();\n}\nMeteor.call('e2e.setRoomKeyID', rid, keyID);","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  return handleSessionExpired();\n}\nMeteor.call('e2e.setRoomKeyID', rid, keyID);","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('e2e.setRoomKeyID', rid, keyID);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    // re-authenticate, then re-run the handshake once\n  }\n}","preventionTips":["Start E2E key exchange only after login resolves","Re-check the session after long-running key generation"],"tags":["e2ee","authentication","meteor-method"],"backgroundTag":"user-not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}