dart 当我故意输入错误的密码或电子邮件时,Flutter Firebase抛出错误[重复]

fgw7neuy  于 2023-11-14  发布在  Flutter
关注(0)|答案(1)|浏览(176)

此问题在此处已有答案

Flutter/Firebase Authentication with Email & Password not functioning as intended [duplicate](1个答案)
18天前关门了。
当我输入了错误的密码或电子邮件地址时,代码并没有抛出正确的异常错误,例如“密码不正确”或“电子邮件不存在”,而是抛出了一个不同的异常。

final _auth = FirebaseAuth.instance;
  Future<void> login() async {
    try {
      await _auth.signInWithEmailAndPassword(
        email: emailController.text,
        password: passwordController.text,
      );
      Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => SignUp_Screen(),
        ),
      );
      // The login was successful, you can perform any necessary actions here.
    } catch (error, stackTrace) {
      debugPrint(error.toString());
      utils().toastMessage(error.toString());
    }
  }

字符串
“登录”按钮。

RoundButton(
                      title: "Login",
                      onTap: () {
                        if (_formKey.currentState!.validate()) {
                          login();
                        }
                      },
                    ),


已在5,257毫秒内重新启动应用程序。fl utter: [firebase_auth/INVALID_LOGIN_CREDENTIALS] Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={FIRAuthErrorUserInfoNameKey=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information., NSUnderlyingError=0x600000e9e460 {Error域=FIRAuthInternalErrorDomain代码=3“(空)”UserInfo={NSUnderlyingError=0x600000ea31e0 {Error Domain=com.google.HTTPStatus Code=400 "(null)" UserInfo={data={length = 224, bytes = 0x7b0a2020 22657272 6f72223a 207b0a20 ... 5d0a2020 7d0a7d0a }, data_content_type=application/json; charset=UTF-8}},

FIRAuthErrorUserInfoDeserializedResponseKey={
flutter:     code = 400;
flutter:     errors =     (
flutter:                 {
flutter:             domain = global;
flutter:             message = "INVALID_LOGIN_CREDENTIALS";
flutter:             reason = invalid;
flutter:         }
flutter:     );
flutter:     message = "INVALID_LOGIN_CREDENTIALS";
flutter: }}}}

jdzmm42g

jdzmm42g1#

使用**FirebaseAuthException**捕获身份验证的异常:

static Future<void> test() async {
    try {
      await FirebaseAuth.instance.signInWithEmailAndPassword(
          email: "[email protected]", password: "password");
    } on FirebaseAuthException catch (e) {
      debugPrint("Exception : ${e.code}");
    }
  }

字符串


的数据

相关问题