Ionic 3 Firebase Phone Authentication not working












3














I am going to authenticate phone number in Ionic 3 using firebase, program runs without error but when I enters phone number then nothing happens..



.html code is below



<ion-item>
<ion-label stacked>Phone Number</ion-label>
<ion-input type="number" [(ngModel)]="phoneNumber"></ion-input>
</ion-item>
<button ion-button id="sign-in-button" (click)="signIn(phoneNumber)">Send OTP</button>
<ion-input type="number" placeholder="OTP" [(ngModel)]="code"></ion-input>
<button ion-button id="verify-in-button" (click)="verify()">Sign In</button>


My .ts file is



 export class HomePage { 
veryficationId : any;
code :string = "";
phoneNumber : number;
constructor(public navCtrl:NavController, public
alertCtrl:AlertController) { }

signIn(phoneNumber)
{
(<any>window).FirebasePlugin.verifyPhoneNumber("+91" +phoneNumber,60,(credential)=>{
this.veryficationId = credential.veryficationId;
}, (error)=> {
alert("error" +error);
} );
}

verify()
{
let signInCredential =
firebase.auth.PhoneAuthProvider.credential(this.veryficationId,this.code);
firebase.auth().signInWithCredential(signInCredential).then((info)=>{
}, (error)=>{
alert("error" +error);
} )
}

}


I don't understand what I am missing...










share|improve this question





























    3














    I am going to authenticate phone number in Ionic 3 using firebase, program runs without error but when I enters phone number then nothing happens..



    .html code is below



    <ion-item>
    <ion-label stacked>Phone Number</ion-label>
    <ion-input type="number" [(ngModel)]="phoneNumber"></ion-input>
    </ion-item>
    <button ion-button id="sign-in-button" (click)="signIn(phoneNumber)">Send OTP</button>
    <ion-input type="number" placeholder="OTP" [(ngModel)]="code"></ion-input>
    <button ion-button id="verify-in-button" (click)="verify()">Sign In</button>


    My .ts file is



     export class HomePage { 
    veryficationId : any;
    code :string = "";
    phoneNumber : number;
    constructor(public navCtrl:NavController, public
    alertCtrl:AlertController) { }

    signIn(phoneNumber)
    {
    (<any>window).FirebasePlugin.verifyPhoneNumber("+91" +phoneNumber,60,(credential)=>{
    this.veryficationId = credential.veryficationId;
    }, (error)=> {
    alert("error" +error);
    } );
    }

    verify()
    {
    let signInCredential =
    firebase.auth.PhoneAuthProvider.credential(this.veryficationId,this.code);
    firebase.auth().signInWithCredential(signInCredential).then((info)=>{
    }, (error)=>{
    alert("error" +error);
    } )
    }

    }


    I don't understand what I am missing...










    share|improve this question



























      3












      3








      3


      1





      I am going to authenticate phone number in Ionic 3 using firebase, program runs without error but when I enters phone number then nothing happens..



      .html code is below



      <ion-item>
      <ion-label stacked>Phone Number</ion-label>
      <ion-input type="number" [(ngModel)]="phoneNumber"></ion-input>
      </ion-item>
      <button ion-button id="sign-in-button" (click)="signIn(phoneNumber)">Send OTP</button>
      <ion-input type="number" placeholder="OTP" [(ngModel)]="code"></ion-input>
      <button ion-button id="verify-in-button" (click)="verify()">Sign In</button>


      My .ts file is



       export class HomePage { 
      veryficationId : any;
      code :string = "";
      phoneNumber : number;
      constructor(public navCtrl:NavController, public
      alertCtrl:AlertController) { }

      signIn(phoneNumber)
      {
      (<any>window).FirebasePlugin.verifyPhoneNumber("+91" +phoneNumber,60,(credential)=>{
      this.veryficationId = credential.veryficationId;
      }, (error)=> {
      alert("error" +error);
      } );
      }

      verify()
      {
      let signInCredential =
      firebase.auth.PhoneAuthProvider.credential(this.veryficationId,this.code);
      firebase.auth().signInWithCredential(signInCredential).then((info)=>{
      }, (error)=>{
      alert("error" +error);
      } )
      }

      }


      I don't understand what I am missing...










      share|improve this question















      I am going to authenticate phone number in Ionic 3 using firebase, program runs without error but when I enters phone number then nothing happens..



      .html code is below



      <ion-item>
      <ion-label stacked>Phone Number</ion-label>
      <ion-input type="number" [(ngModel)]="phoneNumber"></ion-input>
      </ion-item>
      <button ion-button id="sign-in-button" (click)="signIn(phoneNumber)">Send OTP</button>
      <ion-input type="number" placeholder="OTP" [(ngModel)]="code"></ion-input>
      <button ion-button id="verify-in-button" (click)="verify()">Sign In</button>


      My .ts file is



       export class HomePage { 
      veryficationId : any;
      code :string = "";
      phoneNumber : number;
      constructor(public navCtrl:NavController, public
      alertCtrl:AlertController) { }

      signIn(phoneNumber)
      {
      (<any>window).FirebasePlugin.verifyPhoneNumber("+91" +phoneNumber,60,(credential)=>{
      this.veryficationId = credential.veryficationId;
      }, (error)=> {
      alert("error" +error);
      } );
      }

      verify()
      {
      let signInCredential =
      firebase.auth.PhoneAuthProvider.credential(this.veryficationId,this.code);
      firebase.auth().signInWithCredential(signInCredential).then((info)=>{
      }, (error)=>{
      alert("error" +error);
      } )
      }

      }


      I don't understand what I am missing...







      angular typescript firebase firebase-authentication ionic3






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 9 '18 at 15:31









      Sampath

      30.9k17128223




      30.9k17128223










      asked Jan 8 '18 at 17:09









      Sanchit Mahajan

      11311




      11311
























          1 Answer
          1






          active

          oldest

          votes


















          2














          I highly suggest you read this great article from Jorge. It has all the details step by step.



          signIn(phoneNumber: number){
          const appVerifier = this.recaptchaVerifier;
          const phoneNumberString = "+" + phoneNumber;
          firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)
          .then( confirmationResult => {
          // SMS sent. Prompt user to type the code from the message, then sign the
          // user in with confirmationResult.confirm(code).
          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 => {
          confirmationResult.confirm(data.confirmationCode)
          .then(function (result) {
          // User signed in successfully.
          console.log(result.user);
          // ...
          }).catch(function (error) {
          // User couldn't sign in (bad verification code?)
          // ...
          });
          }
          }
          ]
          });
          prompt.present();
          })
          .catch(function (error) {
          console.error("SMS not sent", error);
          });

          }





          share|improve this answer

















          • 1




            It's Working.... Sir...
            – Sanchit Mahajan
            Jan 9 '18 at 15:54










          • Glad to hear that it helped :)
            – Sampath
            Jan 9 '18 at 15:57










          • Not working on device as recaptcha doesn't work on app.
            – Laxmikant Dange
            Jan 21 '18 at 14:00










          • It is only working on PWA...
            – Sanchit Mahajan
            Jan 22 '18 at 16:50










          • Here is the commercial one without captcha: @LaxmikantDange market.ionicframework.com/starters/…
            – Sampath
            Jan 22 '18 at 17:09











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48154903%2fionic-3-firebase-phone-authentication-not-working%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          I highly suggest you read this great article from Jorge. It has all the details step by step.



          signIn(phoneNumber: number){
          const appVerifier = this.recaptchaVerifier;
          const phoneNumberString = "+" + phoneNumber;
          firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)
          .then( confirmationResult => {
          // SMS sent. Prompt user to type the code from the message, then sign the
          // user in with confirmationResult.confirm(code).
          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 => {
          confirmationResult.confirm(data.confirmationCode)
          .then(function (result) {
          // User signed in successfully.
          console.log(result.user);
          // ...
          }).catch(function (error) {
          // User couldn't sign in (bad verification code?)
          // ...
          });
          }
          }
          ]
          });
          prompt.present();
          })
          .catch(function (error) {
          console.error("SMS not sent", error);
          });

          }





          share|improve this answer

















          • 1




            It's Working.... Sir...
            – Sanchit Mahajan
            Jan 9 '18 at 15:54










          • Glad to hear that it helped :)
            – Sampath
            Jan 9 '18 at 15:57










          • Not working on device as recaptcha doesn't work on app.
            – Laxmikant Dange
            Jan 21 '18 at 14:00










          • It is only working on PWA...
            – Sanchit Mahajan
            Jan 22 '18 at 16:50










          • Here is the commercial one without captcha: @LaxmikantDange market.ionicframework.com/starters/…
            – Sampath
            Jan 22 '18 at 17:09
















          2














          I highly suggest you read this great article from Jorge. It has all the details step by step.



          signIn(phoneNumber: number){
          const appVerifier = this.recaptchaVerifier;
          const phoneNumberString = "+" + phoneNumber;
          firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)
          .then( confirmationResult => {
          // SMS sent. Prompt user to type the code from the message, then sign the
          // user in with confirmationResult.confirm(code).
          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 => {
          confirmationResult.confirm(data.confirmationCode)
          .then(function (result) {
          // User signed in successfully.
          console.log(result.user);
          // ...
          }).catch(function (error) {
          // User couldn't sign in (bad verification code?)
          // ...
          });
          }
          }
          ]
          });
          prompt.present();
          })
          .catch(function (error) {
          console.error("SMS not sent", error);
          });

          }





          share|improve this answer

















          • 1




            It's Working.... Sir...
            – Sanchit Mahajan
            Jan 9 '18 at 15:54










          • Glad to hear that it helped :)
            – Sampath
            Jan 9 '18 at 15:57










          • Not working on device as recaptcha doesn't work on app.
            – Laxmikant Dange
            Jan 21 '18 at 14:00










          • It is only working on PWA...
            – Sanchit Mahajan
            Jan 22 '18 at 16:50










          • Here is the commercial one without captcha: @LaxmikantDange market.ionicframework.com/starters/…
            – Sampath
            Jan 22 '18 at 17:09














          2












          2








          2






          I highly suggest you read this great article from Jorge. It has all the details step by step.



          signIn(phoneNumber: number){
          const appVerifier = this.recaptchaVerifier;
          const phoneNumberString = "+" + phoneNumber;
          firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)
          .then( confirmationResult => {
          // SMS sent. Prompt user to type the code from the message, then sign the
          // user in with confirmationResult.confirm(code).
          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 => {
          confirmationResult.confirm(data.confirmationCode)
          .then(function (result) {
          // User signed in successfully.
          console.log(result.user);
          // ...
          }).catch(function (error) {
          // User couldn't sign in (bad verification code?)
          // ...
          });
          }
          }
          ]
          });
          prompt.present();
          })
          .catch(function (error) {
          console.error("SMS not sent", error);
          });

          }





          share|improve this answer












          I highly suggest you read this great article from Jorge. It has all the details step by step.



          signIn(phoneNumber: number){
          const appVerifier = this.recaptchaVerifier;
          const phoneNumberString = "+" + phoneNumber;
          firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)
          .then( confirmationResult => {
          // SMS sent. Prompt user to type the code from the message, then sign the
          // user in with confirmationResult.confirm(code).
          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 => {
          confirmationResult.confirm(data.confirmationCode)
          .then(function (result) {
          // User signed in successfully.
          console.log(result.user);
          // ...
          }).catch(function (error) {
          // User couldn't sign in (bad verification code?)
          // ...
          });
          }
          }
          ]
          });
          prompt.present();
          })
          .catch(function (error) {
          console.error("SMS not sent", error);
          });

          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 9 '18 at 15:31









          Sampath

          30.9k17128223




          30.9k17128223








          • 1




            It's Working.... Sir...
            – Sanchit Mahajan
            Jan 9 '18 at 15:54










          • Glad to hear that it helped :)
            – Sampath
            Jan 9 '18 at 15:57










          • Not working on device as recaptcha doesn't work on app.
            – Laxmikant Dange
            Jan 21 '18 at 14:00










          • It is only working on PWA...
            – Sanchit Mahajan
            Jan 22 '18 at 16:50










          • Here is the commercial one without captcha: @LaxmikantDange market.ionicframework.com/starters/…
            – Sampath
            Jan 22 '18 at 17:09














          • 1




            It's Working.... Sir...
            – Sanchit Mahajan
            Jan 9 '18 at 15:54










          • Glad to hear that it helped :)
            – Sampath
            Jan 9 '18 at 15:57










          • Not working on device as recaptcha doesn't work on app.
            – Laxmikant Dange
            Jan 21 '18 at 14:00










          • It is only working on PWA...
            – Sanchit Mahajan
            Jan 22 '18 at 16:50










          • Here is the commercial one without captcha: @LaxmikantDange market.ionicframework.com/starters/…
            – Sampath
            Jan 22 '18 at 17:09








          1




          1




          It's Working.... Sir...
          – Sanchit Mahajan
          Jan 9 '18 at 15:54




          It's Working.... Sir...
          – Sanchit Mahajan
          Jan 9 '18 at 15:54












          Glad to hear that it helped :)
          – Sampath
          Jan 9 '18 at 15:57




          Glad to hear that it helped :)
          – Sampath
          Jan 9 '18 at 15:57












          Not working on device as recaptcha doesn't work on app.
          – Laxmikant Dange
          Jan 21 '18 at 14:00




          Not working on device as recaptcha doesn't work on app.
          – Laxmikant Dange
          Jan 21 '18 at 14:00












          It is only working on PWA...
          – Sanchit Mahajan
          Jan 22 '18 at 16:50




          It is only working on PWA...
          – Sanchit Mahajan
          Jan 22 '18 at 16:50












          Here is the commercial one without captcha: @LaxmikantDange market.ionicframework.com/starters/…
          – Sampath
          Jan 22 '18 at 17:09




          Here is the commercial one without captcha: @LaxmikantDange market.ionicframework.com/starters/…
          – Sampath
          Jan 22 '18 at 17:09


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48154903%2fionic-3-firebase-phone-authentication-not-working%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)