【发布时间】:2020-06-06 12:58:06
【问题描述】:
我正在使用以下代码进行 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。
- 在 Google 签名中添加了电话号码,并在 Firebase 控制台中启用了电话登录提供商
- 还创建了 SHA 密钥并在 .gradle 文件中添加了 google firebase 插件
我正在使用此代码:https://www.c-sharpcorner.com/article/otp-authentication-in-flutter-using-firebase/
【问题讨论】:
-
Added phone number in Google-sign?您的意思是您在 Firebase 电话身份验证设置中添加了测试电话号码吗?真实的电话号码不适用于模拟器。希望您可以从文档中清楚地了解这一点。 -
是的,我确实在 Google 登录中添加了测试电话号码。但它不起作用
标签: android ios flutter firebase-authentication