ionic 4 firebase如何检查电子邮件是否已存在

时间:2020-03-25 11:51:03

标签: javascript firebase firebase-authentication

我在我的离子应用程序中使用Firebase电话身份验证。登录后,我正在询问用户他们的电子邮件。

如果用户键入Firebase已经存在的电子邮件,则会显示以下消息。

M {code: "auth/email-already-in-use", message: "The email address is already in use by another account."}
code: "auth/email-already-in-use"
message: "The email address is already in use by another account."

但是我无法在离子应用程序中查看如何检查这些错误代码。

我也在发送验证邮件以验证电子邮件

这是代码

我可以使用createUserWithEmailAndPassword来检查错误代码,但是当我进行电话验证时,如何检查错误代码? 预先谢谢你

这是代码 .html

<form [formGroup] = "userDetails">

 <ion-item>
            <ion-label position="floating">Enter your name</ion-label>
            <ion-input formControlName = "name" type = "text"></ion-input>
 </ion-item>

<ion-label position="floating">Enter your email </ion-label>
          <ion-input formControlName = "Email" type = "text"></ion-input>
</ion-item>

          <ion-button type="submit" [disabled]="!userDetails.valid" (click)="submit(Email.value, name.value )">Submit</ion-button>

</form>

.ts

     userDetails = this.fb.group({
            name : ['', [Validators.required, Validators.minLength(3), Validators.maxLength(30), Validators.pattern('[a-zA-Z ]*') ] ],
            Email : ['', [ Validators.required , Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$')  ]],
          })

    submit(email, name ){

    console.log(email)
    console.log(name)


    var mail = email
    let nm = name

this.afauth.authState.subscribe(user =>  {
      if(user) {

    let number = user.phoneNumber

user.updateProfile({
          displayName : nm
        })

          user.updateEmail(mail).then(function(){
              console.log("Email updated")

                user.sendEmailVerification().then(function(){
                  console.log("mail sent")
                }).catch(function(error) {
                  console.log(error)
                })

          }).catch(function(error) {
            console.log(error)
          })         
})      }

0 个答案:

没有答案