RocketChat/Rocket.Chat · error

Invalid user id

Error message

Invalid user id

What it means

deactivate on the users bridge requires a non-empty user id; an empty string or undefined fails with 'Invalid user id' before any lookup. Deactivation has no meaning without a target, and the server treats a blank id as a programming error rather than missing data.

Solutions

  1. Source the id from a fetched user object and check it is a non-empty string.
  2. Return early from the handler when no target user was selected.
  3. If the user may already be gone, check existence first and treat it as a no-op.

Example fix

// before
await deactivate(selectedUserId ?? '', confirmRelinquish, appId);

// after
if (!selectedUserId) {
  return { error: 'Select a user to deactivate' };
}
await deactivate(selectedUserId, confirmRelinquish, appId);
Defensive patterns

Strategy: validation

Validate before calling

if (!userId || userId.trim() === '') {
  return { error: 'A valid user id is required' };
}

Type guard

const isNonEmptyString = (v: unknown): v is string =>
  typeof v === 'string' && v.trim().length > 0;

Prevention

When it happens

Trigger: App calls deactivate with an id from an unset variable, an optional parameter defaulting to '', or reads .id off an undefined user object after a failed lookup.

Common situations: UIKit action handlers with optional data fields; user-picker UI where nothing was selected; refactors dropping the id assignment.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: 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 b2c16d5842)