1

I am using below code for firebase authentication.

 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

I am using Android emulator Pixel API 29.

  1. Added phone number in Google-sign and enable phone signin providers in firebase console
  2. Also created SHA key and also added google firebase plugin in .gradle file

I am using this code : https://www.c-sharpcorner.com/article/otp-authentication-in-flutter-using-firebase/

2
  • 1
    Added phone number in Google-sign ? Did you mean you added test phone numbers in Firebase Phone Auth settings? The real phone numbers will not work for emulators. Hope that is clear for you from the docs. Commented Feb 22, 2020 at 8:15
  • Yes i did add the Test phone number in Google-Sign in. But it is not working Commented Feb 23, 2020 at 2:42

1 Answer 1

1

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

implementation 'androidx.browser:browser:1.3.0'

This will help firebase to open the browser for a reCAPTCHA verification.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.