RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

Thrown by the 'messages/get' Meteor method when Meteor.userId() returns null, i.e. the DDP connection that invoked the method is not authenticated. Meteor methods rely on the connection's login token; without one there is no user context to authorize room access. The error includes { method: 'messages/get' } in its details.

Source

Thrown at apps/meteor/server/publications/messages.ts:296

	if (!type) {
		throw new Meteor.Error('error-param-required', 'The "type" or "lastUpdate" parameters must be provided');
	}

	return handleCursorPagination(type, rid, count, next, previous);
};

Meteor.methods<ServerMethods>({
	async 'messages/get'(
		rid,
		{ lastUpdate, latestDate = new Date(), oldestDate, inclusive = false, count = 20, unreads = false, next, previous, type },
	) {
		check(rid, String);

		const fromId = Meteor.userId();

		if (!fromId) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'messages/get' });
		}

		if (!rid) {
			throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'messages/get' });
		}

		return getMessageHistory(rid, fromId, { lastUpdate, latestDate, oldestDate, inclusive, count, unreads, next, previous, type });
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Ensure login resolved before requesting history (await the login promise or react to Account.onLogin)
  2. Re-authenticate when the token expired and retry the call
  3. For server-side scripts, use an authenticated DDP client or call the underlying service with an explicit userId

Example fix

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

// after
await promiseMeteorCall('login', { resume: token });
Meteor.call('messages/get', rid, {});
Defensive patterns

Strategy: validation

Validate before calling

if (!Meteor.userId()) {
  throw new Error('login required before messages/get');
}
Meteor.call('messages/get', rid, params);

Try / catch

try { await Meteor.callAsync('messages/get', rid, params); } catch (e) { if (e.error === 'error-invalid-user') { /* re-authenticate, then retry once */ } }

Prevention

When it happens

Trigger: Calling Meteor.call('messages/get', ...) before Meteor.loginWithPassword/Token completes; calling after the session token expired and was purged; invoking the method from a server-side context with no authenticated connection.

Common situations: Client boot races where history loads before login finishes; resumed sessions with revoked tokens; test harnesses that call methods on a bare DDP connection.

Related errors


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