gpt4 book ai didi

android - Flutter Firebase 电话身份验证不起作用

转载 作者:行者123 更新时间:2023-12-03 03:38:23 26 4
gpt4 key购买 nike

电话身份验证失败,出现以下异常:

PlatformException(ERROR_SESSION_EXPIRED, 短信验证码已过期。请重新发送验证码重试。, null)

但是,如果我使用与手机不同的电话号码,它会起作用。我已将 Play 商店中的 SHA-1 和 SHA-256 指纹添加到 firebase,并替换了 google-services.json。

这是我的代码:

 void _verifyPhoneNumber() async {
setState(() {
isVerified=true;
});
setState(() {
_message = '';
});
final PhoneVerificationCompleted verificationCompleted =
(AuthCredential phoneAuthCredential) {
_auth.signInWithCredential(phoneAuthCredential);
setState(() {
_message = 'Received phone auth credential: $phoneAuthCredential';

});
};

final PhoneVerificationFailed verificationFailed =
(AuthException authException) {
_message =
'Phone number verification failed';

};

final PhoneCodeSent codeSent =
(String verificationId, [int forceResendingToken]) async {
_verificationId = verificationId;

};

final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
(String verificationId) {
_verificationId = verificationId;
};

await _auth.verifyPhoneNumber(
phoneNumber: '+91'+_phoneNumberController.text,
timeout: const Duration(seconds: 5),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
}

// Example code of how to sign in with phone.
void _signInWithPhoneNumber() async {
setState(() {
isLoading=true;
});
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: _verificationId,
smsCode: _smsController.text,
);
try{
firebaseUser =
(await _auth.signInWithCredential(credential)).user;
final FirebaseUser currentUser = await _auth.currentUser();
assert(firebaseUser.uid == currentUser.uid);
if (firebaseUser != null) {
.....

} else {

_message = 'Sign in failed';
showErrorDialog();
}

}catch (e){
showErrorDialog();
}
setState(() {
isLoading=false;
});
}

最佳答案

不确定您的问题,但它说: ERROR_SESSION_EXPIRED,短信代码已过期_auth.verifyPhoneNumber()您的 超时时间 相当低。试试 60 秒 .

await _auth.verifyPhoneNumber(
phoneNumber: '+91${_phoneNumberController.text}',
timeout: Duration(seconds: 60),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);

如果这没有帮助,请查看 docs .

关于android - Flutter Firebase 电话身份验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59128844/

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