{"record":{"id":"ce911c6c3b4b21d1","repo":"RocketChat/Rocket.Chat","slug":"user-not-logged-in","errorCode":null,"errorMessage":"User not logged in","messagePattern":"User not logged in","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/platform/search.ts","lineNumber":60,"sourceCode":"\t/**\n\t * Search using the current search provider and check if results are valid for the user. The search result has\n\t * the format `{messages:{start:0,numFound:1,docs:[{...}]},users:{...},rooms:{...}}`\n\t * @param text the search text\n\t * @param context the context (uid, rid)\n\t * @param payload custom payload (e.g. for paging)\n\t */\n\tasync 'rocketchatSearch.search'(text, context, payload) {\n\t\tpayload = payload !== null ? payload : undefined; // TODO is this cleanup necessary?\n\n\t\tif (!searchProviderService.activeProvider) {\n\t\t\tthrow new Error('Provider currently not active');\n\t\t}\n\n\t\tSearchLogger.debug({ msg: 'search', text, context, payload });\n\n\t\tconst userId = Meteor.userId();\n\t\tif (!userId) {\n\t\t\tthrow new Error('User not logged in');\n\t\t}\n\n\t\treturn new Promise<IRawSearchResult>((resolve, reject) => {\n\t\t\tvoid searchProviderService.activeProvider?.search(userId, text, context, payload, (error, data) => {\n\t\t\t\tif (error) {\n\t\t\t\t\treturn reject(error);\n\t\t\t\t}\n\n\t\t\t\treturn resolve(data);\n\t\t\t});\n\t\t}).then((result) => validationService.validateSearchResult(result));\n\t},\n\n\tasync 'rocketchatSearch.suggest'(text, context, payload) {\n\t\tpayload ??= undefined; // TODO is this cleanup necessary?\n\n\t\tif (!searchProviderService.activeProvider) {\n\t\t\tthrow new Error('Provider currently not active');","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/platform/search.ts#L42-L78","documentation":"`rocketchatSearch.search` throws a plain `Error('User not logged in')` when `Meteor.userId()` is null. The provider check runs first, so this error only fires on a server where a search provider IS active but the calling connection is anonymous.","triggerScenarios":"`Meteor.call('rocketchatSearch.search', ...)` from a logged-out connection on a server with working search — session expired with the search box still mounted, or unauthenticated scripts calling the method.","commonSituations":"Session expiry while the search UI was open; headless clients calling search without a login step.","solutions":["Authenticate before searching","Gate the search UI on `Meteor.userId()`","Treat this error as session loss: re-login and retry once"],"exampleFix":"// before\nMeteor.call('rocketchatSearch.search', text, context, payload, cb);\n// after\nif (!Meteor.userId()) {\n  return handleSessionExpired();\n}\nMeteor.call('rocketchatSearch.search', text, context, payload, cb);","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  return handleSessionExpired();\n}\nMeteor.call('rocketchatSearch.search', text, context, payload, cb);","typeGuard":null,"tryCatchPattern":"try {\n  const results = await Meteor.callAsync('rocketchatSearch.search', text, context, payload);\n} catch (e) {\n  if (e instanceof Error && e.message === 'User not logged in') {\n    // re-authenticate, then retry once\n  }\n}","preventionTips":["Mount search UI only for authenticated sessions","Treat this message as session expiry, not a search bug","Debounce typeahead so it cannot fire during logout"],"tags":["search","authentication","meteor-method"],"backgroundTag":"user-not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}