RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

The Meteor method wrapper for unfollowMessage requires an authenticated connection: it loads the user with Meteor.userAsync() and throws error-invalid-user when null. The check runs after check(mid, String), so a non-string mid fails earlier with a Match error instead.

Source

Thrown at apps/meteor/server/meteor-methods/messages/unfollowMessage.ts:59

	void notifyOnMessageChange({
		id,
	});

	const isFollowed = false;
	await Apps.self?.triggerEvent(AppEvents.IPostMessageFollowed, message, user, isFollowed);

	return unfollowResult;
};

Meteor.methods<ServerMethods>({
	async unfollowMessage({ mid }) {
		methodDeprecationLogger.method('unfollowMessage', '9.0.0', '/v1/chat.unfollowMessage');
		check(mid, String);

		const user = (await Meteor.userAsync()) as IUser;
		if (!user) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'unfollowMessage' });
		}

		return unfollowMessage(user, { mid });
	},
});

RateLimiter.limitMethod('unfollowMessage', 5, 5000, {
	userId() {
		return true;
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Ensure the session is authenticated before calling unfollowMessage
  2. Re-login and retry once on reconnect
  3. Gate thread follow UI on the logged-in state
Defensive patterns

Strategy: validation

Validate before calling

// client: require an authenticated session and a string mid
if (!Meteor.userId() || typeof mid !== 'string') {
	return;
}
await Meteor.callAsync('unfollowMessage', { mid });

Try / catch

try {
	await Meteor.callAsync('unfollowMessage', { mid });
} catch (e: any) {
	if (e?.error === 'error-invalid-user' && !Meteor.userId()) {
		// re-login and retry once
	}
	throw e;
}

Prevention

When it happens

Trigger: Calling unfollowMessage before login completes; expired resume token after server restart or logout; script/DDL client without a login handshake.

Common situations: Race between page load and login for thread follow actions; long-lived connections that silently became anonymous.

Related errors


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