So I have this issue where every time I add a new user account, it kicks out the current user that is already signed in. I read the firebase api and it said that \"I
I faced the same problem, and I solved it with this way:
When the user login, I save the email and password in the shared preferences. And after creating the user, I login the user again with email and password that I have saved before.
String currentEmail = MyApp.getSharedPreferences().getEmail();
String currentPass = MyApp.getSharedPreferences().getPass();
FirebaseAuth auth = FirebaseAuth.getInstance();
auth.createUserWithEmailAndPassword(email, pass)
.addOnCompleteListener(AddStudent.this, new OnCompleteListener() {
@Override
public void onComplete(@NonNull final Task task) {
if (task.isSuccessful()) {
String currentEmail = MyApp.getSharedPreferences().getEmail();
String currentPass = MyApp.getSharedPreferences().getPass();
//Sign in again
auth.signInWithEmailAndPassword(currentEmail, currentPass)
.addOnCompleteListener(AddStudent.this, new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (!task.isSuccessful()) {
Log.e("RELOGIN", "FAILED");
} else {
Log.e("RELOGIN", "SUCCESS");
}
}
});
finish();
}
}
});