0

I have an admin user who can create a new account to other user. I wrote this code. It did work for first time, then it didn't work. I think it's because of user_ID it will be the same. If it's for this reason, how can I create new account even when I'm logged in?

My code:

mAuth.createUserWithEmailAndPassword(email,password)
   .addOnCompleteListener(
        add_accountActivity.this,
        new OnCompleteListener<AuthResult>() {
           @Override
           public void onComplete(@NonNull Task<AuthResult> task) {
                if (!task.isSuccessful()){
                }else{
                   String user_id = mAuth.getCurrentUser().getUid();
                  // add user Id to database
                    DatabaseReference current_user_db 
                    =FirebaseDatabase.getInstance().getReference()
                   .child("account").child(user_id);
                   current_user_db.setValue(true);
                }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ahmadsq95
  • 1
  • 2
  • You have to signout the current user then you will be able to register new user, as when you sign up then after success you are logged in as a firebase user – Rahul Singh Chandrabhan Mar 15 '18 at 04:05
  • Creating a new account signs in that new user automatically. This means that the existing current user gets signed out. That is working as intended, since the Firebase Authentication SDK for Android is only meant to be used for signing in the current user. Also see my answer here: https://stackoverflow.com/questions/37517208/firebase-kicks-out-current-user (and a workaround that *does* allow creating a new user without signing the current one out after all). – Frank van Puffelen Mar 15 '18 at 04:18
  • To avoid this, try using the Firebase Admin SDK on the server (or use Cloud Functions) to generate as many users you want without logging out. – Charles Crete Mar 15 '18 at 04:19

0 Answers0