{"record":{"id":"c84e7fc363cbbfb8","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-c84e7f","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/unblockUser.ts","lineNumber":24,"sourceCode":"import { unblockUserMethod } from '../../lib/users/unblockUser';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tunblockUser({ rid, blocked }: { rid: string; blocked: string }): boolean;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync unblockUser({ rid, blocked }) {\n\t\tmethodDeprecationLogger.method('unblockUser', '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: 'unblockUser' });\n\t\t}\n\n\t\tawait unblockUserMethod(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/unblockUser.ts#L6-L32","documentation":"Thrown by the deprecated `unblockUser` Meteor method when `Meteor.userId()` is falsy, meaning the method ran without an authenticated user bound to the DDP invocation. The guard exists because `unblockUserMethod(userId, { rid, blocked })` unblocks a user in a room on behalf of a specific caller, so an identity is mandatory. The method is deprecated since 9.0.0 in favor of the REST endpoint `POST /v1/im.blockUser` (it logs a deprecation warning on every call).","triggerScenarios":"Calling `Meteor.call('unblockUser', { rid, blocked })` from a logged-out client; invoking the method in server-side code where no user is bound to the invocation context (raw `Meteor.call` on the server has no userId); a raw DDP method call without a resumed login token.","commonSituations":"Server-side scripts or migrations calling client-facing methods without user context; sessions that expired between page load and the call; automated tests that forget to log a user in; integrations that should be using the REST API with an auth token instead of DDP methods.","solutions":["Log in (or resume the session) on the connection before invoking the method, and check `Meteor.userId()` client-side first.","In server code, skip the method wrapper and call `unblockUserMethod(userId, { rid, blocked })` directly (from `apps/meteor/server/lib/users/unblockUser`) with a known userId.","Migrate to `POST /v1/im.blockUser` with `X-Auth-Token` / `X-User-Id` headers — the method is scheduled for removal in 9.0.0."],"exampleFix":"// before (server-side, no user bound to the invocation)\nMeteor.call('unblockUser', { rid, blocked });\n\n// after — call the underlying API directly with a known userId\nimport { unblockUserMethod } from '../../lib/users/unblockUser';\nawait unblockUserMethod(userId, { rid, blocked });","handlingStrategy":"validation","validationCode":"const userId = Meteor.userId();\nif (!userId) {\n  throw new Error('Login required before unblocking a user');\n}\nMeteor.call('unblockUser', { rid, blocked });","typeGuard":null,"tryCatchPattern":"Meteor.call('unblockUser', { rid, blocked }, (err, res) => {\n  if (err && err.error === 'error-invalid-user') {\n    // session lost: re-authenticate, then retry once\n    return;\n  }\n  if (err) throw err;\n  // use res\n});","preventionTips":["Check Meteor.userId() before invoking user-scoped Meteor methods","Use REST endpoints with token auth for integrations instead of DDP methods","Heed methodDeprecationLogger warnings and migrate to /v1/im.blockUser before 9.0.0"],"tags":["meteor-methods","authentication","user-blocking","deprecated"],"backgroundTag":"user-not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}