RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

The `e2e.setUserPublicAndPrivateKeys` wrapper throws `error-invalid-user` when `Meteor.userId()` is null — publishing an E2E key pair is a per-user operation that requires a session. Deprecated since 9.0.0 in favor of `/v1/e2e.setUserPublicAndPrivateKeys`.

Source

Thrown at apps/meteor/server/meteor-methods/platform/setUserPublicAndPrivateKeys.ts:50

	await Users.setE2EPublicAndPrivateKeysByUserId(userId, {
		private_key: keyPair.private_key,
		public_key: keyPair.public_key,
	});

	const subscribedRoomIds = await Rooms.getSubscribedRoomIdsWithoutE2EKeys(userId);
	await Rooms.addUserIdToE2EEQueueByRoomIds(subscribedRoomIds, userId);

	void notifyOnRoomChangedById(subscribedRoomIds);
};

Meteor.methods<ServerMethods>({
	async 'e2e.setUserPublicAndPrivateKeys'(keyPair) {
		methodDeprecationLogger.method('e2e.setUserPublicAndPrivateKeys', '9.0.0', '/v1/e2e.setUserPublicAndPrivateKeys');
		const userId = Meteor.userId();

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

		if (!keyPair.public_key || !keyPair.private_key) {
			throw new Meteor.Error('error-invalid-keys', 'Invalid keys', {
				method: 'e2e.setUserPublicAndPrivateKeys',
			});
		}

		await setUserPublicAndPrivateKeysMethod(userId, keyPair);
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Log in and confirm `Meteor.userId()` before publishing keys
  2. Handle `error-invalid-user` by re-authenticating and re-running the publish
  3. Migrate to `POST /v1/e2e.setUserPublicAndPrivateKeys`

Example fix

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

Strategy: validation

Validate before calling

if (!Meteor.userId()) {
  return handleSessionExpired();
}
Meteor.call('e2e.setUserPublicAndPrivateKeys', keyPair);

Try / catch

try {
  await Meteor.callAsync('e2e.setUserPublicAndPrivateKeys', keyPair);
} catch (e) {
  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {
    // session dropped during key generation: re-login, regenerate, publish once
  }
}

Prevention

When it happens

Trigger: Calling `Meteor.call('e2e.setUserPublicAndPrivateKeys', keyPair)` from a logged-out connection — key setup racing login, or a retry after the session dropped.

Common situations: E2E key generation starting before authentication completes; session expiry during the key-generation computation (which is slow and often delayed).

Related errors


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