颤振:Firebase在颤振应用程序中向我发送错误代码
我使用Firebase_auth软件包验证电话号码,Firebase发送代码,但当我检查代码的有效性时,它只显示错误。当我打印发送的代码时,它与我收到的代码不同。任何人知道请帮助我。 提前谢谢。 这是我的密码:颤振:Firebase在颤振应用程序中向我发送错误代码,firebase,flutter,firebase-authentication,firebase-cloud-messaging,Firebase,Flutter,Firebase Authentication,Firebase Cloud Messaging,我使用Firebase_auth软件包验证电话号码,Firebase发送代码,但当我检查代码的有效性时,它只显示错误。当我打印发送的代码时,它与我收到的代码不同。任何人知道请帮助我。 提前谢谢。 这是我的密码: await FirebaseAuth.instance.verifyPhoneNumber( timeout: Duration(seconds: 60), phoneNumber: phoneNum
await FirebaseAuth.instance.verifyPhoneNumber(
timeout: Duration(seconds: 60),
phoneNumber: phoneNumber,
verificationCompleted:
(PhoneAuthCredential phoneAuthCredential) {
print(phoneAuthCredential.smsCode);
print("complete");
},
verificationFailed: (e) {
print("failed");
print(e);
},
codeSent: (same, a) {
print(a);
print(same);
Navigator.of(context).pushNamed(
VerifyScreen.routName,
arguments: {
'code': a,
'customerId': customerId,
},
);
},
codeAutoRetrievalTimeout: (sa) {
print(sa);
print("timeout");
},
);
我知道收到的代码无法打印,但它是以加密形式verificationId提供的 验证输入的代码后,将用户输入的代码和
verificationId
发送到Firebase进行验证
如果您的目标是自动验证,而无需通过此verificationCompleted
输入代码,则您可以自动转移用户
注意:前提是sim卡与发送代码的手机位于同一部手机上
其他信息:如果希望该过程是自动的,请使用以下代码:
Future singInPhoneNumber() async {
FirebaseAuth _auth = FirebaseAuth.instance;
_auth.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: Duration(seconds: 60),
verificationCompleted: (AuthCredential phoneAuthCredential) async {
//Automatically verify
Navigator.of(context).pushNamed(
VerifyScreen.routName,
arguments: {
'code': a,
'customerId': customerId,
},
);
debugPrint("Firebase Auth :Auto Verification Completed");
},
verificationFailed: (FirebaseAuthException error) {
debugPrint("ERROR Firebase Auth : AuthException : ${error.message}");
showToast(context, 'Something went wrong, please try again later');
},
codeSent: (String verificationId, [int forceResendingToken]) {
setState(() {
this.verificationId = verificationId;
});
},
codeAutoRetrievalTimeout: (String verificationId) {
return null;
},
);
}
如果您只想手动输入代码:
AuthCredential credential = PhoneAuthProvider.credential(
verificationId: verificationId, smsCode: codeController.text);
_auth
.signInWithCredential(credential)
.then((value) => {
print('The operation completed successfully')
})
.catchError((onError) {
print(onError.toString());
});
非常感谢,很好。欢迎兄弟@Mohammad_Asef