我正在使用以下代码进行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();
}
但是显示以下错误:
[FirebaseAuth:] getGoogleApiForMethod()返回了Gms:com.google.firebase.auth.api.internal.zzaq@847da6d
我正在使用Android模拟器Pixel API 29。
我正在使用以下代码:https://www.c-sharpcorner.com/article/otp-authentication-in-flutter-using-firebase/
答案 0 :(得分:0)
在新的Firebase身份验证版本中,他们进行了重大更改,例如Recaptcha进行人工验证。它需要使用浏览器进行验证,然后在build.gradle文件中添加以下依赖项
implementation 'androidx.browser:browser:1.3.0'
这将帮助Firebase打开浏览器以进行reCAPTCHA验证。