public createNewAccount()

in src/auth/auth-api-request.ts [1532:1590]


  public createNewAccount(properties: CreateRequest): Promise<string> {
    if (!validator.isNonNullObject(properties)) {
      return Promise.reject(
        new FirebaseAuthError(
          AuthClientErrorCode.INVALID_ARGUMENT,
          'Properties argument must be a non-null object.',
        ),
      );
    }

    // Build the signupNewUser request.
    type SignUpNewUserRequest = CreateRequest & {
      photoUrl?: string | null;
      localId?: string;
      mfaInfo?: AuthFactorInfo[];
    };
    const request: SignUpNewUserRequest = deepCopy(properties);
    // Rewrite photoURL to photoUrl.
    if (typeof request.photoURL !== 'undefined') {
      request.photoUrl = request.photoURL;
      delete request.photoURL;
    }
    // Rewrite uid to localId if it exists.
    if (typeof request.uid !== 'undefined') {
      request.localId = request.uid;
      delete request.uid;
    }
    // Construct mfa related user data.
    if (validator.isNonNullObject(request.multiFactor)) {
      if (validator.isNonEmptyArray(request.multiFactor.enrolledFactors)) {
        const mfaInfo: AuthFactorInfo[] = [];
        try {
          request.multiFactor.enrolledFactors.forEach((multiFactorInfo) => {
            // Enrollment time and uid are not allowed for signupNewUser endpoint.
            // They will automatically be provisioned server side.
            if ('enrollmentTime' in multiFactorInfo) {
              throw new FirebaseAuthError(
                AuthClientErrorCode.INVALID_ARGUMENT,
                '"enrollmentTime" is not supported when adding second factors via "createUser()"');
            } else if ('uid' in multiFactorInfo) {
              throw new FirebaseAuthError(
                AuthClientErrorCode.INVALID_ARGUMENT,
                '"uid" is not supported when adding second factors via "createUser()"');
            }
            mfaInfo.push(convertMultiFactorInfoToServerFormat(multiFactorInfo));
          });
        } catch (e) {
          return Promise.reject(e);
        }
        request.mfaInfo = mfaInfo;
      }
      delete request.multiFactor;
    }
    return this.invokeRequestHandler(this.getAuthUrlBuilder(), FIREBASE_AUTH_SIGN_UP_NEW_USER, request)
      .then((response: any) => {
        // Return the user id.
        return response.localId as string;
      });
  }