angularfire身份验证功能以验证是否正在使用电子邮件

时间:2019-10-17 04:20:19

标签: angular typescript authentication firebase-authentication

我知道android angularfire提供了类似于firebase.auth.getinstances()的功能,可以获取并检查是否有任何电子邮件标识符与输入字段匹配以验证电子邮件的可用性。我一直在寻找无用的文档时,Web应用程序是否具有等效功能?

这是我到目前为止所要实现的,我要实现的是能够在继续让用户输入密码之前验证电子邮件

<form novalidate [formGroup]="SignupForm">
  <div *ngIf="!regEmail">
    <div class="form-group w-100">
      <button mat-button type="button" class="btn-google" (click)="authService.GoogleAuth()">
        <i class="fa fa-google"></i>
        Sign up with Google
      </button>
    </div>

    <div class="form-group w-100">
      <button mat-button type="button" class="btn-facebook " (click)="authService.FacebookAuth()">
        <i class="fa fa-facebook"></i>
        Sign up with Facebook
      </button>
    </div>
    <div class="divider w-100">
      <span class="bg-white p-3"><span class="orInner">OR</span></span>
    </div>
    <mat-form-field>
      <input matInput type="email" placeholder="email" formControlName="email" #userEmail>
    </mat-form-field>
    <!--Error codes-->
    <div class="d-flex flex-column align-items-center">
      <div class="form-group w-100">
        <button mat-raised-button type="button" class="w-100" (click)="emailValidate( userEmail.value)">Continue
        </button>
      </div>
    </div>

  </div>

  <div *ngIf="regEmail">
    <mat-form-field>
      <input matInput type="password" placeholder="Password" #userPwd required>
    </mat-form-field>
    <div class="form-group w-100">
      <button mat-raised-button type="button" class="w-100"
        (click)="authService.SignUp( userEmail.value, userPwd.value)">Continue
      </button>
    </div>
  </div>
</form>

对我应该如何在ts中设置emailValidator的含糊感

 emailValidate(email) {
    return this.authService.afAuth.auth.fetchSignInMethodsForEmail(email)
    .then(function(signInMethods) {
      //signInMethod returns ["password"] email not available
          if (signInMethods /*what to i put here */)
            //display verification error
            console.log(signInMethods);
      //signInMethod returns [] email available
      if (signInMethods /*what to i put here */)
      this.regEmail = email;
      })
    }

1 个答案:

答案 0 :(得分:1)

您可以使用Array.includes来检查 id='"+ st.getid() + "'"; 是否包含signInMethods,因此它将类似于

password