【问题标题】:Error : "User not found" with Firebase authentication freezes the app Flutter错误:使用 Firebase 身份验证的“找不到用户”会冻结应用程序 Flutter
【发布时间】:2021-02-18 10:46:56
【问题描述】:

如果用户未注册,则调用signInWithEmailAndPassword 时,应用会崩溃。 我使用 try and catch 来避免它,但似乎没用。 更改数千次后,错误始终相同:

PlatformException (PlatformException(user-not-found, There is no user record corresponding to this identifier. The user may have been deleted.

我正在使用Form 来获取用户输入,也许这就是问题所在? 顺便说一下,在下面的代码中,我手动插入了电子邮件和密码,所以我认为它不关心Forms。 这是代码:

FirebaseAuth auth = FirebaseAuth.instance;

  showErrDialog(BuildContext context, String err) {
    FocusScope.of(context).requestFocus(new FocusNode());
    return showDialog(
      context: context,
      child: AlertDialog(
        title: Text("Error"),
        content: Text(err),
        actions: <Widget>[
          OutlineButton(
            onPressed: () {
              Navigator.pop(context);
            },
            child: Text("Ok"),
          ),
        ],
      ),
    );
  }

  Future<User> signin(
      String email, String password, BuildContext context) async {
    await Firebase.initializeApp();
    try {
      UserCredential result =
          await auth.signInWithEmailAndPassword(email: email, password: email);
      User user = result.user;
      return Future.value(user);
    } catch (e) {
      print(e.code);
      switch (e.code) {
        case 'ERROR_INVALID_EMAIL':
          showErrDialog(context, e.code);
          break;
        case 'ERROR_WRONG_PASSWORD':
          showErrDialog(context, e.code);
          break;
        case 'ERROR_USER_NOT_FOUND':
          showErrDialog(context, e.code);
          break;
        case 'ERROR_USER_DISABLED':
          showErrDialog(context, e.code);
          break;
        case 'ERROR_TOO_MANY_REQUESTS':
          showErrDialog(context, e.code);
          break;
        case 'ERROR_OPERATION_NOT_ALLOWED':
          showErrDialog(context, e.code);
          break;
      }

调用者:

onPressed: () => signin("go@gmail.com", "ciaollllL1", context),

【问题讨论】:

  • 你用的是什么IDE?
  • Visual Studio 代码

标签: firebase flutter firebase-authentication


【解决方案1】:

修复错误

Firebase 更新了他们的软件包,现在他们使用不同的错误代码。您可以使用以下具有新错误代码的函数:

Future<User> signin(String email, String password, BuildContext context) async {
  await Firebase.initializeApp();
  try {
    UserCredential result = await auth.signInWithEmailAndPassword(email: email, password: email);
    User user = result.user;
    return Future.value(user);
  } on FirebaseAuthException catch (e) {
    print(e.code);
    switch (e.code) {
      case 'invalid-email':
        showErrDialog(context, e.code);
        break;
      case 'wrong-password':
        showErrDialog(context, e.code);
        break;
      case 'user-not-found':
        showErrDialog(context, e.code);
        break;
      case 'user-disabled':
        showErrDialog(context, e.code);
        break;
    }
  }
}

修复冻结问题

冻结问题与您的代码无关。问题出在 Visual Studio Code 中。当有Uncaught Exceptions 时,VSCode 会自动添加一个断点。要禁用此功能,请执行以下步骤:

  • 从侧面菜单转到“运行”选项卡

  • 在断点中,禁用 Breakpoints 部分下的 Uncaught Exceptions

【讨论】:

  • 非常有用!谢谢你的朋友。
【解决方案2】:

您是否在 firebase 控制台中授予了权限,并且您是否在 firebase 控制台中添加了 SHA-1 密钥

【讨论】:

  • 当然,但它之前有效...我注册了一些用户,但现在我更改了代码并丢失了以前的版本,所以我不知道发生了什么...是的 SHA-1 密钥存在
猜你喜欢
  • 2021-12-30
  • 1970-01-01
  • 2023-02-04
  • 2020-10-19
  • 2019-12-20
  • 1970-01-01
  • 2021-04-02
  • 1970-01-01
  • 2017-04-11
相关资源
最近更新 更多