How to create an user without sign in with Firebase Auth Android ?
It looks like the accepted solution here is a bit outdated : Firebase create user without sign in
Nowadays, is there any other way ?
How to create an user without sign in with Firebase Auth Android ?
It looks like the accepted solution here is a bit outdated : Firebase create user without sign in
Nowadays, is there any other way ?
Ok, answering myself after some research.
It looks like the situation is the same today. We still have to create an other instance of FirebaseAuth to avoid triggering auth state on the default FirebaseAuth instance you use.
But i suggest a simpler way to do it, without having to provide api key, application id...etc by hand by just using the FirebaseOptions of the default instance.
val firebaseDefaultApp = Firebase.auth.app
val signUpAppName = firebaseDefaultApp.name + "_signUp"
val signUpApp = try {
FirebaseApp.initializeApp(
context,
firebaseDefaultApp.options,
signUpAppName
)
} catch (e: IllegalStateException) {
// IllegalStateException is throw if an app with the same name has already been initialized.
FirebaseApp.getInstance(signUpAppName)
}
// Here is the instance you can use to sign up without triggering auth state on the default Firebase.auth
val signUpFirebaseAuth = Firebase.auth(signUpApp)
How to use ?
signUpFirebaseAuth
.createUserWithEmailAndPassword(email, password)
.addOnSuccessListener {
// Optional, you can send verification email here if you need
// As soon as the sign up with sign in is over, we can sign out the current user
firebaseAuthSignUp.signOut()
}
.addOnFailureListener {
// Log
}