Reputation: 13129
I'm making an app that registers a user which I'm creating manually from Firebase Authentication panel. After I login with that user my Auth is equal to the auth I have on Firebase
So far that login is working nice since after I login with it gaves to my mAuth.getCurrentUser().getUid();
that id.
Now, the problem is the following, in the next Activity I need to create users with a dialog that needs to be stored inside that UID, now I managed to do that in this way.
final UserModel userModel = new UserModel();
userModel.setNombre(nombre);
userModel.setApellido(apellido);
final ProgressDialog pd = new ProgressDialog(mContext);
pd.setMessage("Estamos cargando su paciente...");
pd.setCancelable(false);
pd.show();
final String adminUID = mAuth.getCurrentUser().getUid();
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
pd.dismiss();
final String pacienteID = task.getResult().getUser().getUid();
mDatabase.child("Bord").child(adminUID).child("pacientes").setValue(pacienteID).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Map<String,Object> mapUsuario = new HashMap<>();
mapUsuario.put("nombre",userModel.getNombre());
mapUsuario.put("apellido",userModel.getApellido());
mapUsuario.put("pregunta",1);
mDatabase.child("Bord").child(adminUID).child("pacientes").child(pacienteID).updateChildren(mapUsuario);
}
});
Toast.makeText(mContext, "Su paciente se cargo con exito", Toast.LENGTH_SHORT).show();
mDialog.dismiss();
} else {
pd.dismiss();
Log.i("Tags", "Tags signInWithEmail:failure" + task.getException());
Toast.makeText(mContext, "Su contraseña o email es incorrecta.",
Toast.LENGTH_SHORT).show();
}
This line final String adminUID = mAuth.getCurrentUser().getUid();
before the createUserWithEmailAndPassword
method (from FirebaseAuth to create a new user) is giving to me the mAuth of the first login I made with the user id from the user I created in Firebase console, but after createUserWithEmailAndPassword
I can store that user one time inside my node.
This is how it should work. But the problem relies the second time I press that dialog to add another paciente inside my node.
It seems like createUserWithEmailAndPassword
logged me into firebase after I created my first user, and then, when I tried to add a new one it used the UID from that last user.
So my question is
Is there any way to prevent createUserWithEmailAndPassword
to auto login or change my current userID which I logged in first time ?
Upvotes: 2
Views: 1583
Reputation: 3139
This seems to be by design. But I see two possible solutions:
or
Upvotes: 1