Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71203

Ionic 3 Firebase Phone Authentication not working on phone

$
0
0

@imrangmworld wrote:

Here below is the source code I am using for Firebase phone authentication. This is working fine on browser. But once I create .apk file and tests on my android phone it shows me the exception. alert(“Error: SMS not sent”); It means the following line is not working on phone.
firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)

What could be the issue ?

Source Code:
SignupWithPhone()
{

  let autSer = this.authService;
  const appVerifier = this.recaptchaVerifier;
  if (this.phone.indexOf('+') <= -1) {
     this.phone = "+" + this.phone;
  }

 //alert(this.phone);

  const phoneNumberString = "+" + this.phone;

  firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)
  //this.afAuth.auth.signInWithPhoneNumber(phoneNumberString,appVerifier)
  .then( confirmationResult => {
    // SMS sent. Prompt user to type the code from the message, then sign the
        // confirmationResult.verificationId

          let prompt = this.alertCtrl.create({
          title: 'Enter the Confirmation code',
          inputs: [{ name: 'confirmationCode', placeholder: 'Confirmation Code' }],
          buttons: [
            { text: 'Cancel',
              handler: data => { console.log('Cancel clicked'); }
            },
            { text: 'Send',
              handler: data => {
                // Here we need to handle the confirmation code

                  let signInCredential = firebase.auth.PhoneAuthProvider.credential(confirmationResult.verificationId, data.confirmationCode);
                  autSer.loginWithPhone(signInCredential).subscribe(authData => {
                      this.navCtrl.setRoot(HomePage);
                    }, error => {
                      // in case of login error
                      let alert = this.alertCtrl.create({
                        message: error.message,
                        buttons: ['OK']
                      });
                      alert.present();
                    });

              }
            }
          ]
        });
        prompt.present(); 

  })
  .catch(function (error) { 
    alert("Error: SMS not sent");
    console.log("Error: SMS not sent");
    alert(error);
  });

}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>