FirebaseAuth 无法捕获“用户未找到”和“错误密码”错误[重复]

问题描述 投票:0回答:1

因此,我使用 firebase 为应用程序创建了一个简单的注册兼登录,并编写了此代码用于错误处理。

 switch(e.code) 
                    {
                      case "invalid-email":
                        await showErrorDialog(context,"The entered e-mail format is invalid");// The email id is not in email format
                        break;
                      case "user-not-found":
                        await showErrorDialog(context,"The user is not registered");// The user is a new user/not already registered
                        break;
                      case "wrong-password":
                        await showErrorDialog(context,"wrong password"); // The entered password is wrong
                        break;
                      case "invalid-credential":
                        await showErrorDialog(context,"Invalid username-password combination. Try checking again and enter valid username password info"); // If the entered pair is not available
                        break;                       
                      default:
                        devtools.log("No errors");                     
                    }              

在上面的代码中,showErrorDialog()是一个向用户显示警告的方法,您可以将其替换为打印/日志语句。

我的问题是,假设我注册了一个用户 [电子邮件受保护],密码为“xyz456”。现在我可以使用此凭据正确登录此应用程序。

现在,如果我尝试使用未注册的电子邮件登录,比如说“[电子邮件受保护]”,我应该会收到“用户未找到”错误,但我会收到“无效凭据”错误。同样,如果我输入正确的用户电子邮件并使用错误的密码,我会捕获“无效凭据”错误而不是错误的密码。

但是,如果我输入的电子邮件格式错误,例如“grggvjhj”作为电子邮件 ID,我会正确捕获“无效电子邮件”错误。

TLDR: 无效电子邮件错误正在运行 用户未找到和错误密码不起作用。相反,我得到了“无效凭证”错误代码。

我尝试在文本编辑控制器以及用于保存电子邮件密码值的变量中使用trim()和toString()格式化程序。

我还尝试打印整个错误、e.code 和 e.message,很明显,默认情况下所有错误都被视为“无效凭据”错误。

另一个用户也有类似的问题,但他的问题完全不同,尽管如此,我也尝试了该解决方案,但它对我不起作用。我在这里链接该问题。 Flutter Firebase Auth 返回错误的错误消息

预先感谢您的帮助!

android flutter firebase dart firebase-authentication
1个回答
0
投票

听起来您的项目已开启[针对电子邮件枚举攻击的保护](电子邮件枚举保护),这是 2023 年 9 月 15 日之后创建的所有项目的默认设置。启用该保护后,将不再可能区分

user-not-found
wrong-password
,因为这是一个安全风险。

您要么必须对所有形式的无效凭据采用更通用的流程,要么必须在项目上关闭针对电子邮件枚举攻击的保护。另请参阅我在 Flutter 应用程序中没有收到 Firebase Auth 的错误代码(我只收到 INVALID_LOGIN_CREDENTIALS)

© www.soinside.com 2019 - 2024. All rights reserved.