RocketChat/Rocket.Chat · error · Error

User not logged in

Error message

User not logged in

What it means

`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.

Source

Thrown at apps/meteor/server/meteor-methods/platform/search.ts:60

	/**
	 * Search using the current search provider and check if results are valid for the user. The search result has
	 * the format `{messages:{start:0,numFound:1,docs:[{...}]},users:{...},rooms:{...}}`
	 * @param text the search text
	 * @param context the context (uid, rid)
	 * @param payload custom payload (e.g. for paging)
	 */
	async 'rocketchatSearch.search'(text, context, payload) {
		payload = payload !== null ? payload : undefined; // TODO is this cleanup necessary?

		if (!searchProviderService.activeProvider) {
			throw new Error('Provider currently not active');
		}

		SearchLogger.debug({ msg: 'search', text, context, payload });

		const userId = Meteor.userId();
		if (!userId) {
			throw new Error('User not logged in');
		}

		return new Promise<IRawSearchResult>((resolve, reject) => {
			void searchProviderService.activeProvider?.search(userId, text, context, payload, (error, data) => {
				if (error) {
					return reject(error);
				}

				return resolve(data);
			});
		}).then((result) => validationService.validateSearchResult(result));
	},

	async 'rocketchatSearch.suggest'(text, context, payload) {
		payload ??= undefined; // TODO is this cleanup necessary?

		if (!searchProviderService.activeProvider) {
			throw new Error('Provider currently not active');

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Authenticate before searching
  2. Gate the search UI on `Meteor.userId()`
  3. Treat this error as session loss: re-login and retry once

Example fix

// before
Meteor.call('rocketchatSearch.search', text, context, payload, cb);
// after
if (!Meteor.userId()) {
  return handleSessionExpired();
}
Meteor.call('rocketchatSearch.search', text, context, payload, cb);
Defensive patterns

Strategy: validation

Validate before calling

if (!Meteor.userId()) {
  return handleSessionExpired();
}
Meteor.call('rocketchatSearch.search', text, context, payload, cb);

Try / catch

try {
  const results = await Meteor.callAsync('rocketchatSearch.search', text, context, payload);
} catch (e) {
  if (e instanceof Error && e.message === 'User not logged in') {
    // re-authenticate, then retry once
  }
}

Prevention

When it happens

Trigger: `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.

Common situations: Session expiry while the search UI was open; headless clients calling search without a login step.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/ce911c6c3b4b21d1. Report an issue: GitHub.