当我想在firebase auth上捕获异常时遇到问题
reauthenticateWithCredential();
它什么也抓不到,你知道吗?
下面是示例代码。
AuthCredential credential = EmailAuthProvider.credential(
email: auth.currentUser!.email.toString(),
password: password.toString());
UserCredential userCredential =
await auth.currentUser!.reauthenticateWithCredential(credential);
on FirebaseAuthException catch (e) {
if (e.code == "wrong-password") {
print("Wrong password");}
实验结果:
E/flutter (11690): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/wrong-password] The password is invalid or the user does not have a password.
它没有捕获“错误密码”代码
我尝试用登录函数捕捉同样的问题,结果成功了
下面是一个示例:
void login(String email, String password) async {
try {
await auth.signInWithEmailAndPassword(email: email, password: password);
Get.offAllNamed(Routes.HOME);
} on FirebaseAuthException catch (e) {
if (e.code == "wrong-password") {
print("Wrong password");}
实验结果:
I/flutter (11690): Wrong password
它会捕获“错误密码”代码
1条答案
按热度按时间vfh0ocws1#
这似乎是FlutterFire身份验证问题,请尝试以下操作: