RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

The getChannelHistory Meteor-method wrapper throws 'error-invalid-user' when Meteor.userId() is null — channel history requires an authenticated caller because room-read authorization (Authorization.canReadRoom) is evaluated per user. The method is deprecated since 9.0.0 in favor of GET /v1/channels.history.

Source

Thrown at apps/meteor/server/meteor-methods/messages/getChannelHistory.ts:163

		return {
			messages: messages || [],
			firstUnread,
			unreadNotLoaded,
		};
	}

	return {
		messages: messages || [],
	};
};

Meteor.methods<ServerMethods>({
	async getChannelHistory({ rid, latest, oldest, inclusive, offset = 0, count = 20, unreads, showThreadMessages = true }) {
		methodDeprecationLogger.method('getChannelHistory', '9.0.0', '/v1/channels.history');
		check(rid, String);

		if (!Meteor.userId()) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getChannelHistory' });
		}

		const fromUserId = Meteor.userId();
		if (!fromUserId) {
			return false;
		}

		return getChannelHistory({ rid, fromUserId, latest, oldest, inclusive, offset, count, unreads, showThreadMessages });
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Check Meteor.userId() first; re-authenticate when null
  2. Switch to GET /v1/channels.history with an auth token (deprecation target)
  3. Make history loaders retry once after a re-login instead of failing the panel

Example fix

// before
Meteor.call('getChannelHistory', { rid });

// after
if (!Meteor.userId()) {
  // re-login before loading history
}
Meteor.call('getChannelHistory', { rid });
Defensive patterns

Strategy: validation

Validate before calling

if (!Meteor.userId()) {
  // re-login before loading history
} else {
  Meteor.call('getChannelHistory', { rid, latest, oldest, inclusive, offset, count });
}

Try / catch

try {
  const history = await Meteor.callAsync('getChannelHistory', params);
} catch (e) {
  if ((e as Meteor.Error).error === 'error-invalid-user') {
    // session expired mid-scroll: re-auth and reload the history panel
  }
}

Prevention

When it happens

Trigger: Meteor.call('getChannelHistory', { rid, latest, oldest, ... }) from an expired, revoked, or anonymous DDP session.

Common situations: Infinite-scroll / history loaders firing after token expiry; integrations fetching history over DDP without login; long-lived dashboards that outlive their session.

Related errors


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