window.FirebasePlugin.verifyPhoneNumber function response unable to use it

Viewed 382

I have implemented firebase phone authentication mechanism to login user with following code:

(<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);
        });
  } 

but credential.verificationId value can't able to store or send to another page

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));})
}

How to resolve above error?

1 Answers

You should get the parameters from the nav params, directly it won't work. try

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));
    })
 }

i hope this will help you.

For your reference check this article https://medium.com/@gbrigens/ionic-3-phone-authentication-with-firebase-dbed967e95ef

Related