I am encountering an issue where multiple entries are being created in my Firebase Authentication database with same provider. As shown in the attached image, duplicate entries are being generated.
Image of multiple entries with same email and same provider
I guess there is nothing to do with the code but I am attaching just in case of you need it
{
if (_formKey.currentState!.validate()) {
try {
if (!privacyStatus) {
appFlutterToast("Please check privacy policy check box!");
return;
}
QuerySnapshot<Map<String, dynamic>> querySnapshot = await FirebaseFirestore.instance
.collection("users")
.where("username", isEqualTo: usernameController.text.trim())
.get();
if (querySnapshot.docs.isNotEmpty) {
appFlutterToast("Username Not Available");
return;
}
final credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: emailController.text.trim(),
password: passwordController.text,
);
if (credential.user == null) {
appFlutterToast("Error");
} else {
appFlutterToast("Registered Successful");
FirebaseFirestore.instance.collection("users").doc(credential.user!.uid).set(
{'id': credential.user!.uid, 'uid': credential.user!.uid, "username": usernameController.text.trim()},
SetOptions(merge: true));
SharedPreferences pref = await SharedPreferences.getInstance();
await context.read<UserProvider>().getCurrentAuth(context);
await pref.setBool('logged', true);
///MAIN LANDING PAGE
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => const MyCardsScreen()),
);
}
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
appFlutterToast("The password provided is too weak.");
// print('The password provided is too weak.');
} else if (e.code == 'email-already-in-use') {
appFlutterToast("account already exists for that email.");
// print('The account already exists for that email.');
} else {
appFlutterToast(e.message ?? "Error");
}
} catch (e) {
// print(e);
}
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(content: Text('User added')),
// );
}
// await users.add({
// 'username': nameText,
// 'password': passwordText,
// }).then((value) => print("user added"));
}
Final result should be just one entry for one email.
Thank you in advance.
Saurabh Prajapati is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.