I am trying to create a new user in Firebase. I am using the auth.createUserWithEmailAndPassword
method but it does not create a new entry in the firebase db.
Here is my code:
final newUser = await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
if (newUser != null) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const VerifyEmailScreen()),
);
} else {
setState(() {
registrationFail = true;
});
}
I get an error message "An undefined error happened" which is the default error message in the catch code and then it just hangs.
I’m not sure I am communicating with Firebase. How do I check to see if I am talking to the db?
I have searched for a solution but everything is very old and nothing works.
Any help would be greatly appreciated.
Thanks
2
Answers
The
createUserWithEmailAndPassword
API exists on Firebase Authentication, not in Cloud Firestore. So it creates a new record for the user in Firebase Authentication, but won’t create anything in Firestore.If you want to write to Firestore, check its API docs here.
If you’re getting an error message that is vague, it might be that email enumeration protection is enabled on your project – which intentionally hides a lot of detail from API responses to prevent against attacks. To see if this is the case, you may want to temporarily disable the protection and see if you get a clearer error message.
To troubleshoot this issue, you can re-check the following setup carefully.
google-services.json
file within your project directory.main.dart
.It helps to understand the issue.
You can find your entry here:
Hope your code will run as you expected.