RocketChat/Rocket.Chat · error · Error

Invalid user id

Error message

Invalid user id

What it means

Thrown by the users bridge deactivate method when userId is falsy. Deactivation calls convertById and setUserActiveStatus with the id, so an empty id is rejected before any database lookup to avoid deactivating the wrong (or no) user.

Source

Thrown at apps/meteor/app/apps/server/bridges/users.ts:170

			);
		}

		if (!Object.keys(updateFields).length) {
			return true;
		}

		await Users.updateOne({ _id: user.id }, { $set: updateFields as any });

		void notifyOnUserChange({ clientAction: 'updated', id: user.id, diff: updateFields });

		return true;
	}

	protected async deactivate(userId: IUser['id'], confirmRelinquish: boolean, appId: string): Promise<boolean> {
		this.orch.debugLog(`The App ${appId} is deactivating a user.`);

		if (!userId) {
			throw new Error('Invalid user id');
		}

		// #TODO: #AppsEngineTypes - Remove explicit types and typecasts once the apps-engine definition/implementation mismatch is fixed.
		const convertedUser: IUser | undefined = await this.orch.getConverters()?.get('users').convertById(userId);
		const { id: uid } = convertedUser as IUser;

		await setUserActiveStatus(uid, false, confirmRelinquish);

		return true;
	}

	protected async setActiveState(
		userId: IUser['id'],
		state: Pick<IUser, 'statusDefault' | 'statusSource' | 'statusText' | 'statusExpiresAt' | 'statusId'>,
		appId: string,
	): Promise<void> {
		this.orch.debugLog(`The App ${appId} is setting active state for user ${userId}`);

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Validate that userId is a non-empty string before calling deactivate.
  2. Resolve the user id from a trusted source and skip the call when it is missing.
  3. Guard the event handler boundary against empty payloads.

Example fix

// before
await users.deactivate(maybeUserId, true);

// after
if (!maybeUserId) {
  return;
}
await users.deactivate(maybeUserId, true);
Defensive patterns

Strategy: validation

Validate before calling

if (!userId) {
  throw new Error('Cannot deactivate: userId is required');
}

Type guard

function isValidUserId(id: unknown): id is string {
  return typeof id === 'string' && id.length > 0;
}

Prevention

When it happens

Trigger: App calls deactivate with an empty string, null, or undefined userId — usually because a user reference was not resolved upstream.

Common situations: App acts on a deletion/removal event whose user id field was empty; refactor left a placeholder; chained call forwarded an undefined value.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/a748c7558f6854e1. Report an issue: GitHub.