RocketChat/Rocket.Chat · error · Error
CustomOAuth: Failed to extract custom name
Error message
CustomOAuth: Failed to extract custom name
What it means
Thrown by getCustomName's catch block when something inside the try throws. Unlike username/email, an empty nameField lookup is NOT an error (it falls back to getName, which tries name/username/nickname/preferred_username/...). So this wrapper fires only when fromTemplate itself throws — practically an invalid nameField template, e.g., a malformed {{regex::path}} formula whose regex fails to compile — since getName's plain property reads cannot throw.
Source
Thrown at apps/meteor/server/lib/auth-providers/custom-oauth/customOAuth.ts:168
throw new Meteor.Error('field_not_found', `Email field "${this.emailField}" not found in data`);
}
return value as string;
} catch (error) {
throw new Error('CustomOAuth: Failed to extract email', { cause: error });
}
}
getCustomName(data: Record<string, any>) {
try {
const value = fromTemplate(this.nameField, data);
if (!value) {
return this.getName(data);
}
return value as string;
} catch (error) {
throw new Error('CustomOAuth: Failed to extract custom name', { cause: error });
}
}
getAvatarUrl(data: Record<string, any>) {
try {
const value = fromTemplate(this.avatarField, data);
if (!value) {
logger.debug({ msg: 'Avatar field not found in data', avatarField: this.avatarField, data });
}
return value as string;
} catch (error) {
throw new Error('CustomOAuth: Failed to extract avatar url', { cause: error });
}
}
getName(identity: Record<string, any>): string {
const name = (identity.name ||View on GitHub (pinned to b2c16d5842)
Solutions
- Correct or simplify the nameField template (valid dot path like 'user.displayName' or a well-formed '{{/^([^@]+)@/::email}}' formula)
- Test the template against a sample payload before saving: fromTemplate(nameField, sampleIdentity) should not throw
- If the display name is not critical, clear nameField — Rocket.Chat then derives a name via getName without erroring on missing fields
Example fix
// before
nameField: '{{/((/::name}}' // invalid regex -> throws
// after
nameField: 'name' Defensive patterns
Strategy: validation
Validate before calling
import { fromTemplate } from './transform_helpers';
// smoke-test the template before saving OAuth config
const sample = { name: 'Jane Doe', email: 'jane@example.com' };
fromTemplate(nameField, sample); // throws here if the template regex is invalid — fix before deploy Try / catch
try {
await oauthLogin();
} catch (e) {
if (e instanceof Error && e.message === 'CustomOAuth: Failed to extract custom name') {
// nameField template is malformed — check e.cause for the SyntaxError
} else throw e;
} Prevention
- Validate field templates (dot paths and {{regex::path}} formulas) in a unit test before saving them
- Prefer plain dot-path mappings unless regex extraction is truly needed
- Remember: a missing name is NOT an error (falls back to getName) — only broken templates throw
When it happens
Trigger: nameField configured with a broken template such as '{{/((/::name}}' (new RegExp throws SyntaxError inside getRegexpMatch); template braces mismatched so replacement/regex parsing throws during a custom OAuth login.
Common situations: Hand-written regex templates in the OAuth field-mapping config; copy-paste from docs with smart quotes or missing delimiters; template syntax change after upgrades.
Related errors
- CustomOAuth: Failed to extract avatar url
- CustomOAuth: Failed to extract custom name
- CustomOAuth: Failed to extract avatar url
- field_not_found
- CustomOAuth: Failed to extract username
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/06563a968bb6c476.
Report an issue: GitHub.