RocketChat/Rocket.Chat · error · Error

CustomOAuth: Failed to extract email

Error message

CustomOAuth: Failed to extract email

What it means

Generic wrapper thrown by getEmail's catch block; the meaningful failure is error.cause, normally Meteor.Error('field_not_found') from error 637, occasionally a fromTemplate syntax error (invalid {{regex::path}} email template). It surfaces during login as the outermost error of the email-extraction step.

Source

Thrown at apps/meteor/server/lib/auth-providers/custom-oauth/customOAuth.ts:154

			}

			return value as string;
		} catch (error) {
			throw new Error('CustomOAuth: Failed to extract username', { cause: error });
		}
	}

	getEmail(data: Record<string, any>) {
		try {
			const value = fromTemplate(this.emailField, data);

			if (!value) {
				logger.debug({ msg: 'Email field not found in data', emailField: this.emailField, data });
				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>) {

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Inspect error.cause (field_not_found includes the emailField template) and the 'Email field not found in data' debug entry
  2. Fix the emailField mapping or grant the email scope, then retry login
  3. Clear emailField if the deployment does not require email-based account mapping
Defensive patterns

Strategy: try-catch

Try / catch

try {
	await oauthLogin();
} catch (e) {
	const cause = (e as Error & { cause?: unknown }).cause;
	if (cause instanceof Meteor.Error && cause.error === 'field_not_found') {
		// cause.reason names the emailField — grant email scope or fix the path
	} else throw e;
}

Prevention

When it happens

Trigger: emailField mapping resolves to nothing in the provider's identity payload; malformed emailField template causing fromTemplate to throw; any unexpected error inside the try block (e.g., non-object data from a weird IdP response).

Common situations: Debugging shows 'CustomOAuth: Failed to extract email' but the actionable detail (which field, what data) is in cause and the debug log one frame deeper.

Related errors


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