[英]signInWithCredential returns null without any error in flutter
我正在使用 Firebase 使用电话号码登录,它确实会发送 OTP 消息,但是当我尝试使用我获得的 OTP 和验证 ID 使用凭据进行签名时(它们不是 null,它们确实有值)它在此处返回 Z37A6259CC0C1DAEFF094 (结果为空)不抛出任何错误这是我的代码
static Future<UserCredential?> verifyOTP(
String verificationId, String otp) async {
UserCredential? result;
try {
print(otp);
print(verificationId);
PhoneAuthCredential credential = PhoneAuthProvider.credential(
verificationId: verificationId,
smsCode: otp,
);
result = await _firebaseAuth?.signInWithCredential(credential);
User? user = _firebaseAuth?.currentUser;
print('user $user');
print('results $result');
} on FirebaseAuthException catch (error) {
print(error);
}
return result;
}
通过signInWithCredential
您是指Email and Password
Firebase 身份验证吗?
如果是这样,您应该使用signInWithEmailAndPassword
Firebase Auth 方法。 下面的例子:
try {
await _firebaseAuth.signInWithEmailAndPassword(
email: email,
password: password,
);
} catch (_) {
throw const LogInWithEmailAndPasswordFailure();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.