window.FirebasePlugin.verifyPhoneNumber函数响应无法使用它

时间:2018-11-15 12:27:16

标签: android firebase ionic-framework ionic3 firebase-authentication

我已经实现了Firebase电话身份验证机制,通过以下方式登录用户 代码:

(<any>window).FirebasePlugin.verifyPhoneNumber('+91'+this.phone, 60, function (credential) {
          //alert("sms sent successfully"+ credential.verificationId);
          //this.verificationId = credential.verificationId;
           let modal = this.modalCtrl.create(verificationPage,{verificationId: credential.verificationId});
           modal.present();

        }, error => {
           alert(JSON.stringify(error));
          console.log("error: " + error);
        });
  } 

但是credential.verificationId值无法存储或发送到另一个页面

verify() {
    this.signInCredential = firebase.auth.PhoneAuthProvider.credential(this.verificationId, this.code);
    alert("u"+JSON.stringify(this.signInCredential));
    firebase.auth().signInWithCredential(this.signInCredential).then((info) => { alert("check"+JSON.stringify(info));}, (error) => {
    alert("err"+JSON.stringify(error));})
}

如何解决以上错误?

1 个答案:

答案 0 :(得分:0)

您应该从导航参数中获取参数,否则将无法正常工作。 尝试

constructor(public params: Navparams){
 }
 verify() {
   let verificationId = params.get("verificationId");
   this.signInCredential = 
   firebase.auth.PhoneAuthProvider.credential(verificationId, this.code);
   alert("u"+JSON.stringify(this.signInCredential));
   firebase.auth().signInWithCredential(this.signInCredential).then((info) =>
    { 
     alert("check"+JSON.stringify(info));}, (error) => {
     alert("err"+JSON.stringify(error));
    })
 }

我希望这会对您有所帮助。

供您参考,请查看此文章 https://medium.com/@gbrigens/ionic-3-phone-authentication-with-firebase-dbed967e95ef