So, after 1 week reading, trying & failing.
I finally got it.
A way to SignUp a user without signing out the current user, this helps a lot if you have an app/webapp where the user signup other users (like a WebManager App)
Firebase SDK is designed to auth the new credentials set by the client and sign in without asking.
So, having this info, we need to create a second app inside our main app just to generate the credentials and then deleting the created app after we finish to set up everything at firebase and firestore.
Instructions:
Create a Custom Action named manageUser that will return a string non-nullable.
with 3 parameters.
* emailAddress
* password
* random
the random argument you are going to fill it with a Random String with min 10 to 25 length (upper,lower,digits)
The random is the name of the app that is going to be generated in the code so if multiple users are using this action at the same time it doesnt overlap.
Paste this little code inside the custom code section:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
Future<String> createClient(
// Parameters
String emailAddress, //Email from Widget State
String password, //Password from Widget State
String randomDocGen, //Random String (min 10 max 25 - upper/lowe/digits)
)
async {
//Create the return msg
String returnmsg='Success';
//created time variable
DateTime createdTime = DateTime.now();
//Create the secondary app to create the users
FirebaseApp app = await Firebase.initializeApp(
name: randomDocGen, options: Firebase.app().options);
try {
//Create the user with the email & password provided
UserCredential userCredential = await FirebaseAuth.instanceFor(app: app)
.createUserWithEmailAndPassword(
email: emailAddress, password: password);
// Set the UID generated to a variable so we can use it later
String? uid = userCredential.user?.uid;
// Check if UID is not empy
if (uid != null) {
//Get collection reference to create our new user document
final CollectionReference<Map<String, dynamic>> usersRef =
FirebaseFirestore.instance.collection('users');
//Create new user document with the parameters we have (you can add more parameters and just add here the extra)
usersRef.doc(uid).set({
'uid': uid,
'email': emailAddress,
'created_time': createdTime,
});
return returnmsg;
} else {
return "Error while creating the UID";
}
} on FirebaseAuthException catch (e) {
return e.code;
}
}
Custom Code View
Parameters
Random Parameter :
and that's it.
Hope it helps a lot that want to create users from an already signed in user