RocketChat/Rocket.Chat · error · Error

CustomOAuth: Failed to extract custom name

Error message

CustomOAuth: Failed to extract custom name

What it means

getCustomName() maps nameField over the identity payload. Unlike username/e-mail, a missing value does not throw - it falls back to getName(), which tries name, username, nickname, CharacterName, userName, preferred_username and user.name in order. This error therefore means fromTemplate() itself threw: practically always an invalid regular expression inside a '{{/regex/::path}}' nameField (SyntaxError in new RegExp()), or nameField being undefined when the method is called directly.

Source

Thrown at apps/meteor/server/lib/auth-providers/custom-oauth/custom_oauth_server.js:350

				throw new Meteor.Error('field_not_found', `Email field "${this.emailField}" not found in data`, data);
			}
			return value;
		} catch (error) {
			throw new Error('CustomOAuth: Failed to extract email', error.message);
		}
	}

	getCustomName(data) {
		try {
			const value = fromTemplate(this.nameField, data);

			if (!value) {
				return this.getName(data);
			}

			return value;
		} catch (error) {
			throw new Error('CustomOAuth: Failed to extract custom name', error.message);
		}
	}

	getAvatarUrl(data) {
		try {
			const value = fromTemplate(this.avatarField, data);

			if (!value) {
				logger.debug({ msg: 'Avatar field not found in data', avatarField: this.avatarField, data });
			}
			return value;
		} catch (error) {
			throw new Error('CustomOAuth: Failed to extract avatar url', error.message);
		}
	}

	getName(identity) {
		const name =

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Replace the nameField formula with a plain dot path that exists in the payload, e.g. 'display_name' or 'user.full_name'
  2. If a regex is required, compile-check it first: new RegExp('<your regex>') must not throw, and it should have exactly one capture group
  3. Clear Name Field to use the built-in fallback chain (name, username, nickname, CharacterName, userName, preferred_username, user.name)

Example fix

// before: Name Field = '{{/(.+/::displayName}}'  // unbalanced regex -> SyntaxError
// Error: CustomOAuth: Failed to extract custom name ...

// after: Name Field = 'display_name'
Defensive patterns

Strategy: validation

Validate before calling

// compile-check a nameField formula before saving the OAuth config
const assertNameTemplateCompiles = (tpl: string) => {
  const m = /^/((?!/::).*)/::(.+)/.exec(tpl);
  if (m) new RegExp(m[1]); // throws SyntaxError now, not during everyone's login
};

Type guard

const isValidNameTemplate = (tpl: string): boolean => {
  try {
    const m = /^/((?!/::).*)/::(.+)/.exec(tpl);
    if (m) new RegExp(m[1]);
    return true;
  } catch {
    return false;
  }
};

Try / catch

try {
  identity.name = strategy.getCustomName(identity);
} catch (error) {
  logger.warn(error.message);
  identity.name = strategy.getName(identity); // built-in fallback chain
}

Prevention

When it happens

Trigger: nameField set to '{{/(.+/::displayName}}' (unbalanced regex) so new RegExp throws during login; a template whose path portion triggers a TypeError; calling getCustomName on a strategy constructed without nameField.

Common situations: Admin reuses a username/avatar regex formula for the Name Field and breaks it; copy-paste introduces smart quotes or missing braces; provider payload change makes the path resolve against a primitive.

Related errors


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