function validateAuthFactorInfo()

in src/auth/auth-api-request.ts [248:303]


function validateAuthFactorInfo(request: AuthFactorInfo): void {
  const validKeys = {
    mfaEnrollmentId: true,
    displayName: true,
    phoneInfo: true,
    enrolledAt: true,
  };
  // Remove unsupported keys from the original request.
  for (const key in request) {
    if (!(key in validKeys)) {
      delete request[key];
    }
  }
  // No enrollment ID is available for signupNewUser. Use another identifier.
  const authFactorInfoIdentifier =
      request.mfaEnrollmentId || request.phoneInfo || JSON.stringify(request);
  // Enrollment uid may or may not be specified for update operations.
  if (typeof request.mfaEnrollmentId !== 'undefined' &&
      !validator.isNonEmptyString(request.mfaEnrollmentId)) {
    throw new FirebaseAuthError(
      AuthClientErrorCode.INVALID_UID,
      'The second factor "uid" must be a valid non-empty string.',
    );
  }
  if (typeof request.displayName !== 'undefined' &&
      !validator.isString(request.displayName)) {
    throw new FirebaseAuthError(
      AuthClientErrorCode.INVALID_DISPLAY_NAME,
      `The second factor "displayName" for "${authFactorInfoIdentifier}" must be a valid string.`,
    );
  }
  // enrolledAt must be a valid UTC date string.
  if (typeof request.enrolledAt !== 'undefined' &&
      !validator.isISODateString(request.enrolledAt)) {
    throw new FirebaseAuthError(
      AuthClientErrorCode.INVALID_ENROLLMENT_TIME,
      `The second factor "enrollmentTime" for "${authFactorInfoIdentifier}" must be a valid ` +
      'UTC date string.');
  }
  // Validate required fields depending on second factor type.
  if (typeof request.phoneInfo !== 'undefined') {
    // phoneNumber should be a string and a valid phone number.
    if (!validator.isPhoneNumber(request.phoneInfo)) {
      throw new FirebaseAuthError(
        AuthClientErrorCode.INVALID_PHONE_NUMBER,
        `The second factor "phoneNumber" for "${authFactorInfoIdentifier}" must be a non-empty ` +
        'E.164 standard compliant identifier string.');
    }
  } else {
    // Invalid second factor. For example, a phone second factor may have been provided without
    // a phone number. A TOTP based second factor may require a secret key, etc.
    throw new FirebaseAuthError(
      AuthClientErrorCode.INVALID_ENROLLED_FACTORS,
      'MFAInfo object provided is invalid.');
  }
}