在 flutter firebase 中登录时出现错误

Nea*_*eal 4 dart firebase firebase-authentication flutter

在使用错误的电子邮件或密码登录时,我希望获得我输入的小吃栏,但我的控制台中出现错误。

错误 -

操作 RecaptchaAction(action=signInWithPassword) 的初始任务失败,但出现异常 - 发生内部错误。[ 无效的登录凭证]。

验证服务代码 -

  Future<UserCredential> signInUser(String email, String password) async {
    UserCredential userCredential = await _auth.signInWithEmailAndPassword(
      email: email,
      password: password,
    );
    return userCredential;
  }
Run Code Online (Sandbox Code Playgroud)

登录代码 -

Future<void> signIn() async {
    try {
      if (emailController.text.trim().isEmpty) {
        return showWarningSnackBar(context, 'Empty Email');
      }
      if (passwordController.text.trim().isEmpty) {
        return showWarningSnackBar(context, 'Empty Password');
      }

      await AuthService().signInUser(
        emailController.text.trim(),
        passwordController.text.trim(),
      );
      if (!context.mounted) return;
      showSnackBar(context, 'Successfully logged in');
    } on FirebaseAuthException catch (e) {
      if (e.code == 'user-not-found') {
        showErrorSnackBar(context, 'No user found for that email.');
      } else if (e.code == 'wrong-password') {
        showErrorSnackBar(context, 'Wrong password provided for that user.');
      } else if (e.code == 'INVALID_LOGIN_CREDENTIALS') {
        showErrorSnackBar(context, 'Login credentials are invalid.');
      } else if (e.code == 'invalid-email') {
        showErrorSnackBar(context, 'The email address is badly formatted.');
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

我还没有尝试过任何东西

小智 5

在遇到类似的问题后,我认为这个问题可能是因为启用了“电子邮件枚举保护”。

“电子邮件枚举是一种暴力攻击,恶意行为者试图通过将电子邮件地址传递给 API 并检查响应来猜测或确认系统中的用户。”

https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection

该链接详细说明了如何禁用它。

希望这可以帮助。