I'm trying to make an app with firebase (authentication) which allows a teacher to create his student's user, then send the student the username and password and let him log in. My problem is that in order to do so, after the teacher is creating the user, the current user is the student's, and when I'm trying to do the following code:
private void signStu(String email,String password)
{
final FirebaseUser teacher=mAuth.getCurrentUser();
mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
FirebaseUser student=mAuth.getCurrentUser();
User newUser=new User(/*data i need to pass to the constructor, doesn't affect the result*/);
mAuth.updateCurrentUser(teacher); //Here it passes on the student user and not the teacher
}
});
}
So it seems like the mAuth.getCurrentUser() is updated to all of its usages before, so the teacher variable becomes the student variable after it's created. Anyone got any idea of how to fix that, or a way to work around that? Thanks !