{"record":{"id":"7edaddc5aa33ff3c","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-7edadd","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/fetchMyKeys.ts","lineNumber":19,"sourceCode":"import type { ServerMethods } from '@rocket.chat/ddp-client';\nimport { Users } from '@rocket.chat/models';\nimport { Meteor } from 'meteor/meteor';\n\nimport { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\t'e2e.fetchMyKeys'(): { public_key?: string; private_key?: string };\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync 'e2e.fetchMyKeys'() {\n\t\tmethodDeprecationLogger.method('e2e.fetchMyKeys', '9.0.0', '/v1/e2e.fetchMyKeys');\n\t\tconst userId = Meteor.userId();\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'e2e.fetchMyKeys' });\n\t\t}\n\t\treturn Users.fetchKeysByUserId(userId);\n\t},\n});\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/platform/fetchMyKeys.ts#L1-L24","documentation":"Thrown by 'e2e.fetchMyKeys' when there is no authenticated user. The method returns the caller's end-to-end encryption key pair via Users.fetchKeysByUserId(userId); without a session there is no user whose keys could be returned. The method is deprecated since 9.0.0 in favor of /v1/e2e.fetchMyKeys (named by its deprecation logger).","triggerScenarios":"Fetching E2E keys during encrypted-room setup from an expired session; calling the method during the login/logout transition; scripts invoking it without authentication.","commonSituations":"E2E key handshake on clients whose token expired; long-lived tabs resuming E2E setup; migrations to the REST endpoint in 9.x.","solutions":["Restore the session (re-login) before requesting E2E keys","Guard the call with Meteor.userId() and restart E2E setup after login","Migrate to GET /v1/e2e.fetchMyKeys with an authenticated request (the method already logs this deprecation)"],"exampleFix":"// before\nconst keys = await Meteor.callAsync('e2e.fetchMyKeys');\n\n// after\nif (!Meteor.userId()) {\n  // E2E setup must wait for a session\n  return restartE2ESetupAfterLogin();\n}\nconst keys = await Meteor.callAsync('e2e.fetchMyKeys');","handlingStrategy":"validation","validationCode":"// client: E2E key retrieval requires a session\nif (!Meteor.userId()) {\n  // defer E2E setup until after login\n}","typeGuard":"import { Meteor } from 'meteor/meteor';\n\nconst isMeteorError = (err: unknown, code?: string): err is Meteor.Error =>\n  err instanceof Meteor.Error && (code === undefined || err.error === code);","tryCatchPattern":"try {\n  const keys = await Meteor.callAsync('e2e.fetchMyKeys');\n} catch (err) {\n  if (isMeteorError(err, 'error-invalid-user')) {\n    // restart E2E setup after re-authentication\n  } else {\n    throw err;\n  }\n}","preventionTips":["Sequence E2E key fetch after login state is confirmed","Migrate to GET /v1/e2e.fetchMyKeys for new code — the DDP method is deprecated in 9.0.0"],"tags":["meteor","authentication","rocket-chat","e2e-encryption","deprecated-api"],"backgroundTag":"user-not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}