RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

The E2E suggested-group-key handler (accept/reject) requires an acting user, and it throws this Meteor.Error when the userId argument is null — i.e. there is no authenticated user in the method invocation context. Without a user there is no subscription to look up, so the operation cannot proceed.

Source

Thrown at apps/meteor/server/lib/e2e/functions/handleSuggestedGroupKey.ts:13

import { Rooms, Subscriptions } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { notifyOnSubscriptionChangedById, notifyOnRoomChangedById } from '../../notifyListener';

export async function handleSuggestedGroupKey(
	handle: 'accept' | 'reject',
	rid: string,
	userId: string | null,
	method: string,
): Promise<void> {
	if (!userId) {
		throw new Meteor.Error('error-invalid-user', 'Invalid user', { method });
	}

	const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId);
	if (!sub) {
		throw new Meteor.Error('error-subscription-not-found', 'Subscription not found', { method });
	}

	const suggestedKey = String(sub.E2ESuggestedKey ?? '').trim();
	if (!suggestedKey) {
		throw new Meteor.Error('error-no-suggested-key-available', 'No suggested key available', { method });
	}

	if (handle === 'accept') {
		// A merging process can happen here, but we're not doing that for now
		// If a user already has oldRoomKeys, we will ignore the suggested ones
		const oldKeys = sub.oldRoomKeys ? undefined : sub.suggestedOldRoomKeys;
		await Subscriptions.setGroupE2EKeyAndOldRoomKeys(sub._id, suggestedKey, oldKeys);
		const { modifiedCount } = await Rooms.removeUsersFromE2EEQueueByRoomId(sub.rid, [userId]);

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Make the call from an authenticated session so this.userId is populated
  2. If invoking the handler from server code, pass an explicit, existing userId instead of null
Defensive patterns

Strategy: validation

Validate before calling

const userId = Meteor.userId() /* or this.userId in a method */;
if (!userId) {
  // require login before showing/invoking the suggested-key action
}

Type guard

const isUserId = (userId: string | null | undefined): userId is string =>
  typeof userId === 'string' && userId.trim().length > 0;

Prevention

When it happens

Trigger: The Meteor method delegating to handleSuggestedGroupKey runs with this.userId null — unauthenticated client invocation, or server-side code calling the handler without passing a user id.

Common situations: Expired login token on a client that still fires the EEE key dialog action; custom code invoking the method via Meteor.call without a user context; refactors that dropped the userId argument.

Related errors


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