{"record":{"id":"44388758bec1f92c","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-443887","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/setUserPublicAndPrivateKeys.ts","lineNumber":50,"sourceCode":"\n\tawait Users.setE2EPublicAndPrivateKeysByUserId(userId, {\n\t\tprivate_key: keyPair.private_key,\n\t\tpublic_key: keyPair.public_key,\n\t});\n\n\tconst subscribedRoomIds = await Rooms.getSubscribedRoomIdsWithoutE2EKeys(userId);\n\tawait Rooms.addUserIdToE2EEQueueByRoomIds(subscribedRoomIds, userId);\n\n\tvoid notifyOnRoomChangedById(subscribedRoomIds);\n};\n\nMeteor.methods<ServerMethods>({\n\tasync 'e2e.setUserPublicAndPrivateKeys'(keyPair) {\n\t\tmethodDeprecationLogger.method('e2e.setUserPublicAndPrivateKeys', '9.0.0', '/v1/e2e.setUserPublicAndPrivateKeys');\n\t\tconst userId = Meteor.userId();\n\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'e2e.setUserPublicAndPrivateKeys',\n\t\t\t});\n\t\t}\n\n\t\tif (!keyPair.public_key || !keyPair.private_key) {\n\t\t\tthrow new Meteor.Error('error-invalid-keys', 'Invalid keys', {\n\t\t\t\tmethod: 'e2e.setUserPublicAndPrivateKeys',\n\t\t\t});\n\t\t}\n\n\t\tawait setUserPublicAndPrivateKeysMethod(userId, keyPair);\n\t},\n});\n","sourceCodeStart":32,"sourceCodeEnd":64,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/platform/setUserPublicAndPrivateKeys.ts#L32-L64","documentation":"The `e2e.setUserPublicAndPrivateKeys` wrapper throws `error-invalid-user` when `Meteor.userId()` is null — publishing an E2E key pair is a per-user operation that requires a session. Deprecated since 9.0.0 in favor of `/v1/e2e.setUserPublicAndPrivateKeys`.","triggerScenarios":"Calling `Meteor.call('e2e.setUserPublicAndPrivateKeys', keyPair)` from a logged-out connection — key setup racing login, or a retry after the session dropped.","commonSituations":"E2E key generation starting before authentication completes; session expiry during the key-generation computation (which is slow and often delayed).","solutions":["Log in and confirm `Meteor.userId()` before publishing keys","Handle `error-invalid-user` by re-authenticating and re-running the publish","Migrate to `POST /v1/e2e.setUserPublicAndPrivateKeys`"],"exampleFix":"// before\nMeteor.call('e2e.setUserPublicAndPrivateKeys', keyPair);\n// after\nif (!Meteor.userId()) {\n  return handleSessionExpired();\n}\nMeteor.call('e2e.setUserPublicAndPrivateKeys', keyPair);","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  return handleSessionExpired();\n}\nMeteor.call('e2e.setUserPublicAndPrivateKeys', keyPair);","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('e2e.setUserPublicAndPrivateKeys', keyPair);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    // session dropped during key generation: re-login, regenerate, publish once\n  }\n}","preventionTips":["Re-check the session after key generation — it can outlive the login token","Publish keys immediately after login, not from detached background tasks","Migrate to /v1/e2e.setUserPublicAndPrivateKeys"],"tags":["e2ee","authentication","deprecated","meteor-method"],"backgroundTag":"user-not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}