【问题标题】:Authentification whith phone number with firebase in ionic3 [closed]在ionic 3中使用firebase的电话号码进行身份验证[关闭]
【发布时间】:2018-02-05 22:41:39
【问题描述】:

我只想创建一个带有电话号码身份验证的 ionic 移动应用程序(使用 firebase),但我不知道应该如何进行。有人可以帮助我吗?谢谢。

【问题讨论】:

    标签: angular typescript firebase firebase-authentication ionic3


    【解决方案1】:

    您需要执行以下步骤:

    Activate Phone Number Authentication in your Firebase Console.
    Set up reCAPTCHA verifier.
    Send the SMS
    Sign the user in.
    

    .html

    <ion-content padding>
      <div id="recaptcha-container"></div>
    
      <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)">
        Sign In
      </button>
    
    </ion-content>
    

    .ts

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

    这里是Great article about it。我从这篇文章中提取了上面的代码。

    Offical doc

    【讨论】:

    • 谢谢你@Sampath。我会试试的
    • 确定。没问题:)
    • 它给了我那个错误(错误:./node_modules/firebase/utils/promise.js)我会尝试修复它,但如果你有任何想法......
    • 现在好了。谢谢你:)
    • 我只是意识到这不适用于移动设备
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 2020-01-28
    相关资源
    最近更新 更多