RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-name

error-invalid-name

Error message

Invalid name

What it means

First content validation inside addOAuthApp: applicationParams.name must exist, be a string (checked via typeof valueOf()), and not trim to an empty string. The REST layer's ajv schema already requires a string, so in practice the trim check is what fires (whitespace-only names pass ajv but fail here); a missing or non-string name only reaches this line from direct/internal calls.

Source

Thrown at apps/meteor/server/lib/auth/oauth2-server/addOAuthApp.ts:27

export async function addOAuthApp(applicationParams: OauthAppsAddParams, uid: IUser['_id'] | undefined): Promise<IOAuthApps> {
	if (!uid) {
		throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'addOAuthApp' });
	}

	const user = await Users.findOneById(uid, { projection: { username: 1 } });

	if (!user?.username) {
		// TODO: username is required, but not always present
		throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'addOAuthApp' });
	}

	if (!(await hasPermissionAsync(uid, 'manage-oauth-apps'))) {
		throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'addOAuthApp' });
	}

	if (!applicationParams.name || typeof applicationParams.name.valueOf() !== 'string' || applicationParams.name.trim() === '') {
		throw new Meteor.Error('error-invalid-name', 'Invalid name', { method: 'addOAuthApp' });
	}

	if (
		!applicationParams.redirectUri ||
		typeof applicationParams.redirectUri.valueOf() !== 'string' ||
		applicationParams.redirectUri.trim() === ''
	) {
		throw new Meteor.Error('error-invalid-redirectUri', 'Invalid redirectUri', {
			method: 'addOAuthApp',
		});
	}

	if (typeof applicationParams.active !== 'boolean') {
		throw new Meteor.Error('error-invalid-arguments', 'Invalid arguments', {
			method: 'addOAuthApp',
		});
	}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Send a non-empty, meaningful application name
  2. Trim inputs client-side before submitting (name.trim() !== '')
  3. For direct calls, validate params with the same OauthAppsAddParams shape the REST schema enforces

Example fix

// before
{ "name": "   ", "active": true, "redirectUri": "https://app.example.com/cb" }

// after
{ "name": "My Integration", "active": true, "redirectUri": "https://app.example.com/cb" }
Defensive patterns

Strategy: type-guard

Validate before calling

// client-side, before POST /api/v1/oauth-apps.create
const name = String(form.name ?? '').trim();
if (!name) throw new Error('Application name is required');
await post('/oauth-apps.create', { ...form, name });

Type guard

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

const isValidAppParams = (p: unknown): p is { name: string; active: boolean; redirectUri: string } =>
  typeof p === 'object' && p !== null && isNonEmptyString((p as any).name) && isNonEmptyString((p as any).redirectUri) && typeof (p as any).active === 'boolean';

Try / catch

try {
  await addOAuthApp(params, uid);
} catch (error) {
  if (error instanceof Meteor.Error && error.error === 'error-invalid-name') {
    setFieldError('name', 'Enter a non-empty application name');
  } else {
    throw error;
  }
}

Prevention

When it happens

Trigger: POST /api/v1/oauth-apps.create with body { name: ' ', active: true, redirectUri: '...' }; a direct addOAuthApp call omitting name or passing a number/object; form inputs submitted after the user cleared the field but left spaces.

Common situations: UI forms not trimming inputs; scripts posting placeholder values; client-side joins producing whitespace strings.

Related errors


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