How to do Phone Authentication in Flutter using Firebase?

前端 未结 6 1647
刺人心
刺人心 2021-02-02 02:27

I have searched many websites and I didn\'t find a way to implement phone authentication in Flutter using Firebase. Can anyone tell me how to this?

6条回答
  •  [愿得一人]
    2021-02-02 02:52

    I had the same issue but I was building an Ionic app.

    you can do firebase phone auth on the web. the idea is:

    • take the user's phone number and send to a webpage.
    • create a recaptchaVerifier

      var recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');
      
    • sign in the user with phone number:

      firebase.auth().signInWithPhoneNumber(phoneNumber, recaptchaVerifier)
              .then(confirmationResult => {
                  myVerificationId = confirmationResult.verificationId;
              })
              .catch(error => {
                  console.log('error', error);
              })
      
    • send the confirmation id back to the flutter app through a deeplink

    • Firebase will send the sms code.

    • sign in the user with any method that takes the confirmation Id and the code as parameters. for the web it goes like this:

        let signinCredintial = firebase.auth.PhoneAuthProvider.credential(this.verificationId, this.code);
        firebase.auth().signInWithCredential(signinCredintial)
         .then(response => {
           // user is signed in
      
      })
      

提交回复
热议问题