I had an issue where i need to create different types of users with different forms (because every type of users have a completely type of data) but when you create multiple signup forms the only one working is the last one you create (dont know why) so i created this custom action from firebase_auth to generate multiple create account forms. Sharing this in case you need it.
[image.png]Dependency: firebase_auth
import 'package:firebase_auth/firebase_auth.dart';
Future createUserFlutterFire(
String emailAddress,
String password
) async {
String returnAuth = "Success";
try {
await FirebaseAuth.instance
.createUserWithEmailAndPassword(email: emailAddress, password: password);
} on FirebaseAuthException catch (e) {
returnAuth = e.code;
}
return returnAuth;
}
EDIT: Well after a few more things i added to the same function to create the Document of the user, in case you need it
[image.png]Code:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
Future createUserFlutterFire(
String emailAddress,
String password
)
async {
String? returnAuth = "Valid";
try {
await FirebaseAuth.instance
.createUserWithEmailAndPassword(email: emailAddress, password: password);
if (FirebaseAuth.instance.currentUser != null) {
final CollectionReference> usersRef =
FirebaseFirestore.instance.collection('users');
usersRef.doc(FirebaseAuth.instance.currentUser?.uid).set({
'uid': FirebaseAuth.instance.currentUser?.uid,
'email': emailAddress
});
}
} on FirebaseAuthException catch (e) {
returnAuth = e.code;
}
return returnAuth;
}
In this function i dont add more than the UID and the EMAIL, and then i use the FF action "Update Document" to finish up the fields in the form. Like this: [image.png]The moment you create the user you automatically get the user reference so no need to log in or something like that, just update directly to user reference Enjoy!