{"record":{"id":"e6812098cc0536b5","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-e68120","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/messages/messageSearch.ts","lineNumber":114,"sourceCode":"\t\t\t\tdocs: await Messages.find(query, {\n\t\t\t\t\t// @ts-expect-error col.s.db is not typed\n\t\t\t\t\treadPreference: readSecondaryPreferred(Messages.col.s.db),\n\t\t\t\t\t...options,\n\t\t\t\t}).toArray(),\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\tlogger.error({ msg: 'Error while finding messages', error });\n\t\tthrow new Error('error-while-finding-messages', { cause: error });\n\t}\n};\n\nMeteor.methods<ServerMethods>({\n\tasync messageSearch(text, rid, limit, offset) {\n\t\tmethodDeprecationLogger.method('messageSearch', '9.0.0', '/v1/chat.search');\n\t\tconst currentUserId = Meteor.userId();\n\t\tif (!currentUserId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'messageSearch',\n\t\t\t});\n\t\t}\n\n\t\treturn messageSearch(currentUserId, text, rid, limit, offset);\n\t},\n});\n","sourceCodeStart":96,"sourceCodeEnd":122,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/messages/messageSearch.ts#L96-L122","documentation":"messageSearch runs a workspace message search on behalf of the caller and requires identity to authorize room-scoped results: Meteor.userId() returning null throws error-invalid-user before the search backend is consulted. The method is deprecated since 9.0.0 in favor of /v1/chat.search.","triggerScenarios":"Meteor.call('messageSearch', text, rid, limit, offset) from a logged-out tab, with an invalidated resume token, or from an unauthenticated DDP client.","commonSituations":"Search boxes used after session expiry; custom search UIs mounted outside the authenticated shell; bots calling the DDP method without a login step.","solutions":["Check Meteor.userId() before invoking search and disable the search box when logged out","Re-authenticate on session-invalidated events, then retry","Migrate to /v1/chat.search which authenticates via REST token"],"exampleFix":"// before\nconst result = await Meteor.callAsync('messageSearch', text, rid, limit, offset);\n\n// after\nif (!Meteor.userId()) {\n  // search requires a logged-in user\n} else {\n  const result = await Meteor.callAsync('messageSearch', text, rid, limit, offset);\n}","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  // message search requires a logged-in user\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await Meteor.callAsync('messageSearch', text, rid, limit, offset);\n} catch (error) {\n  if (error instanceof Meteor.Error && error.error === 'error-invalid-user') {\n    // session expired — re-authenticate, then retry\n  } else {\n    throw error;\n  }\n}","preventionTips":["Disable the search box in logged-out states","Migrate integrations to /v1/chat.search (the DDP method is deprecated since 9.0.0)","Handle session-expiry centrally so search re-authenticates transparently"],"tags":["authentication","search","meteor-method","legacy"],"backgroundTag":"not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}