{"record":{"id":"e9d09b1126567149","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-e9d09b","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/users/blockUser.ts","lineNumber":24,"sourceCode":"import { blockUserMethod } from '../../lib/users/blockUser';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tblockUser({ rid, blocked }: { rid: string; blocked: string }): boolean;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync blockUser({ rid, blocked }) {\n\t\tmethodDeprecationLogger.method('blockUser', '9.0.0', '/v1/im.blockUser');\n\t\tcheck(rid, String);\n\t\tcheck(blocked, String);\n\n\t\tconst userId = Meteor.userId();\n\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'blockUser' });\n\t\t}\n\n\t\tawait blockUserMethod(userId, { rid, blocked });\n\n\t\treturn true;\n\t},\n});\n","sourceCodeStart":6,"sourceCodeEnd":32,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/users/blockUser.ts#L6-L32","documentation":"The `blockUser` Meteor method checks `Meteor.userId()` after argument checks and throws `error-invalid-user` when there is no authenticated session. The method is deprecated since 9.0.0 in favor of the REST endpoint `POST /v1/im.blockUser`. The actual blocking logic lives in `blockUserMethod`, which can throw further domain errors — this one is purely the authentication gate.","triggerScenarios":"Calling `Meteor.call('blockUser', { rid, blocked })` while unauthenticated: before login resolves, after logout, with an expired resume token, or from server-side code without a user context.","commonSituations":"Blocking from a stale logged-out tab; UI actions racing the login flow on page load; integrations still on the deprecated DDP method without a session; version upgrades where clients were migrated to REST but old calls remain in caches.","solutions":["Ensure the user is logged in (`Meteor.userId()` non-null) before invoking `blockUser`.","Migrate to the REST endpoint `POST /api/v1/im.blockUser` with an auth token — the DDP method is deprecated since 9.0.0.","Re-authenticate on connection invalidation and retry the block."],"exampleFix":"// before (deprecated DDP method)\nMeteor.call('blockUser', { rid, blocked });\n\n// after - use the REST endpoint with an authenticated session\nawait fetch('/api/v1/im.blockUser', {\n  method: 'POST',\n  headers: { 'X-Auth-Token': token, 'X-User-Id': uid, 'Content-Type': 'application/json' },\n  body: JSON.stringify({ rid, blocked }),\n});","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  return;\n}\n// preferred: authenticated REST instead of the deprecated DDP method\nawait fetch('/api/v1/im.blockUser', { method: 'POST', headers: { 'X-Auth-Token': token, 'X-User-Id': uid, 'Content-Type': 'application/json' }, body: JSON.stringify({ rid, blocked }) });","typeGuard":"const isAuthenticated = (): boolean => typeof Meteor.userId() === 'string';","tryCatchPattern":"try {\n  await Meteor.callAsync('blockUser', { rid, blocked });\n} catch (e: any) {\n  if (e?.error === 'error-invalid-user' && !Meteor.userId()) {\n    // authentication gate (not 'user not found'): re-login and retry\n  }\n}","preventionTips":["Migrate off the deprecated blockUser method to POST /v1/im.blockUser (deprecated since 9.0.0).","Disable block/unblock UI until the session is authenticated.","Watch deprecation logs to catch remaining DDP calls before removal."],"tags":["meteor","users","block","authentication","deprecated"],"backgroundTag":"authentication-required","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}