简体   繁体   English

Flutter中的Firebase电话身份验证问题

[英]firebase phone authentication problem in flutter

I am using below code for firebase authentication.我正在使用以下代码进行 firebase 身份验证。

 void NavigateToOtp(){
      //Navigate to another screen
    }
    Future<void> verifyPhone() async {
      final PhoneCodeSent smsOTPSent = (String verId, [int forceCodeResend]) {
        this.verificationId = verId;
      };
      try {
        await _auth.verifyPhoneNumber(
            phoneNumber: '+XX XXXXXXXXXX', // PHONE NUMBER TO SEND OTP
            codeAutoRetrievalTimeout: (String verId) {
              //Starts the phone number verification process for the given phone number.
              //Either sends an SMS with a 6 digit code to the phone number specified, or sign's the user in and [verificationCompleted] is called.
              this.verificationId = verId;
            },
            codeSent:
            smsOTPSent, // WHEN CODE SENT THEN WE OPEN DIALOG TO ENTER OTP.
            timeout: const Duration(seconds: 20),
            verificationCompleted: (AuthCredential phoneAuthCredential) {
              print(_auth.currentUser());
              print(phoneAuthCredential);
              NavigateToOtp();

            },
            verificationFailed: (AuthException exceptio) {
              print('${exceptio.message}');
            });
      } catch (e) {
        handleError(e);
      }
    }

    void sendOtp(){
      verifyPhone();
    }

But is showing me below error :但向我显示以下错误:

[FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@847da6d [FirebaseAuth: ] getGoogleApiForMethod() 返回 Gms:com.google.firebase.auth.api.internal.zzaq@847da6d

I am using Android emulator Pixel API 29.我正在使用 Android 模拟器 Pixel API 29。

  1. Added phone number in Google-sign and enable phone signin providers in firebase console在 Google 签名中添加电话号码并在 firebase 控制台中启用电话登录提供程序
  2. Also created SHA key and also added google firebase plugin in .gradle file还创建了 SHA 密钥并在 .gradle 文件中添加了 google firebase 插件

I am using this code : https://www.c-sharpcorner.com/article/otp-authentication-in-flutter-using-firebase/我正在使用此代码: https : //www.c-sharpcorner.com/article/otp-authentication-in-flutter-using-firebase/

In the new Firebase auth version, they've made major changes like Recaptcha for human verification.it needs a browser to verify so, Add below dependency to your build.gradle file在新的 Firebase auth 版本中,他们进行了重大更改,例如用于人工验证的 Recaptcha。它需要浏览器来验证,将以下依赖项添加到您的 build.gradle 文件中

implementation 'androidx.browser:browser:1.3.0'

This will help firebase to open the browser for a reCAPTCHA verification.这将有助于 firebase 打开浏览器进行 reCAPTCHA 验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM