node.js - 在Flutter App中检查Firebase Auth中是否已存在电子邮件

标签 node.js firebase flutter dart firebase-realtime-database

通过电子邮件和密码进行注册时可以使用,但是当我使用已经注册的ID时,它不会显示错误。相反,它重定向到主页,并在控制台中显示PlatformException(ERROR_EMAIL_ALREADY_IN_USE, The email address is already in use by another account

Future validateForm() async {
FormState formState = _formKey.currentState;
if (formState.validate()) {
  FirebaseUser user = await firebaseAuth.currentUser();
  if (user == null) {
    firebaseAuth
        .createUserWithEmailAndPassword(
            email: _emailTextController.text,
            password: _passwordTextController.text)
        .then((user) => {
              _userServices.createUser(user.user.uid, {
                "username": _nameTextController.text,
                "email": _emailTextController.text,
                "userId": user.user.uid,
                "gender": gender,
              }),
            })
        .catchError((err) {
      showDialog(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              title: Text("User Already Exists"),
              content: Text(err.message),
              actions: [
                FlatButton(
                  child: Text("Ok"),
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                )
              ],
            );
          });
    });
    Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => HomePage()));
  } else {
    return ("already a user");
  }
}

}

最佳答案

您将进入第二页,因为您有:

   Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => HomePage()));

if块之后。因此,如果user == null将输入if,然后进入catchError,然后导航至HomePage,则应将上述代码移至else:
  } else {
  Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => HomePage()));
    return ("already a user");
  }

关于node.js - 在Flutter App中检查Firebase Auth中是否已存在电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60986401/

相关文章:

javascript - WebStorm - 制作 node_modules "library root"但也将其排除在索引之外

android - 我会因为看到真实广告(展示次数)而被 AdMob 禁止吗?

node.js - nodeJS请求方法不起作用,我是现收现付计划

firebase - Flutter Firebase Auth/Google 登录运行时类型错误

flutter - 如何调用 CupertinoPicker

node.js - 为什么 npm 抛出错误 "checksum failed while installing @angular/cli"?

angularjs - 在nodejs环回中安排一个cron作业

javascript - 使用 node.js 在生产模式下缩小脚本/CSS

node.js - 管理员 Firebase 错误 : "admin.auth(...).generatePasswordResetLink is not a function"

flutter - dartdoc 失败 : Top level package requires Flutter but FLUTTER_ROOT environment variable not set