通过电子邮件和密码进行注册时可以使用,但是当我使用已经注册的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/