【发布时间】:2020-03-26 11:18:32
【问题描述】:
电话身份验证失败,出现以下异常:
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;
});
}
【问题讨论】:
-
Check this post 可能你会得到你的解决方案。
标签: android firebase flutter dart firebase-authentication