RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

The `e2e.setRoomKeyID` wrapper throws `error-invalid-user` when `Meteor.userId()` is null — submitting a room E2E key id requires an authenticated connection, since the key is attributed to and authorized against the logged-in user.

Source

Thrown at apps/meteor/server/meteor-methods/platform/setRoomKeyID.ts:40

	const room = await Rooms.setE2eKeyId(rid, keyID);

	if (!room) {
		throw new Meteor.Error('error-room-e2e-key-already-exists', 'E2E Key ID already exists', {
			method: 'e2e.setRoomKeyID',
		});
	}

	void notifyOnRoomChanged(room);
};

Meteor.methods<ServerMethods>({
	async 'e2e.setRoomKeyID'(rid, keyID) {
		check(rid, String);
		check(keyID, String);

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

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

		await setRoomKeyIDMethod(userId, rid, keyID);
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Log in before starting the E2E key exchange
  2. Check `Meteor.userId()` first and route to login when absent
  3. Re-run the key exchange after re-authenticating

Example fix

// before
Meteor.call('e2e.setRoomKeyID', rid, keyID);
// after
if (!Meteor.userId()) {
  return handleSessionExpired();
}
Meteor.call('e2e.setRoomKeyID', rid, keyID);
Defensive patterns

Strategy: validation

Validate before calling

if (!Meteor.userId()) {
  return handleSessionExpired();
}
Meteor.call('e2e.setRoomKeyID', rid, keyID);

Try / catch

try {
  await Meteor.callAsync('e2e.setRoomKeyID', rid, keyID);
} catch (e) {
  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {
    // re-authenticate, then re-run the handshake once
  }
}

Prevention

When it happens

Trigger: Calling `Meteor.call('e2e.setRoomKeyID', rid, keyID)` while logged out — session expired during the E2E handshake or the flow started pre-login.

Common situations: E2E setup racing the login flow; retries after logout.

Related errors


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