gpt4 book ai didi

firebase - _auth.signInWithCredential不起作用(卡住)

转载 作者:行者123 更新时间:2023-12-03 04:43:43 25 4
gpt4 key购买 nike

我遇到了Firebase电话身份验证的问题,在该问题中,当我使用_auth.signInWithCredential()时,它不会从功能中消失并卡在那里。
这是我的代码:

Future<void> verifyPhoneNumber(String phoneNumber) async {
await _auth.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: Duration(seconds: 60),
verificationCompleted: (AuthCredential credential) async {
print('Verification OTP completed');
AuthResult result = await _auth.signInWithCredential(credential);
FirebaseUser user = result.user;
if (user != null) {
print('User is not null!');
Navigator.pushReplacementNamed(context, 'home');
}
},
verificationFailed: (AuthException exception) async {
print('There was a problem sending the otp');
print(exception.code);
print(exception.message);
},
codeSent: (String verificationID, [int forceResendingToken]) {

createAlertDialog(context, widget.isFromGoogleAuth, verificationID);
},
codeAutoRetrievalTimeout: null);
}
接下来,当用户按下按钮时,我运行此命令:
onTap: (pin) async {
otpText = pin.trim();
print('$otpText');
AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: verificationID, smsCode: otpText);
print('${verificationID}');
print('${credential.providerId}');

//everything until now has been printed, nothing is null

AuthResult authResult = await _auth
.signInWithCredential(credential)
.then((value) {

//this value is not printed

print('${value.user.phoneNumber}');
});

//The next line of code doesnt get run, and it doesnt print value.user.phone number

print('I HAVE REACHED HERE');
FirebaseUser user = authResult.user;
if (user != null) {
Navigator.pushReplacementNamed(context, 'home');
} else {}
},

最佳答案

问题在于,在测试用户中,我添加了我的电话号码,而不是使用在其中分配的OTP代码,而是使用一些发送到我的电话的旧OTP代码,这导致signInWithCredential引发错误。感谢您的帮助,我非常感谢

关于firebase - _auth.signInWithCredential不起作用(卡住),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62658649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com