Skip to content Skip to sidebar Skip to footer

Reauthenticate User X From An "admin User" To Delete User X

In others Firebase version with removeUser we can delete an user only using email and password. With the new Firebase version it seems you can only delete and user if you have conn

Solution 1:

The Firebase SDK for Android can only delete the currently logged in user. So if you know the user's email+password, you'll have to sign in as that user to delete the account.

For admin functionality you should use the Firebase Admin SDK, which you should run on a trusted back-end server. Authentication functionality currently is only available in the Firebase Admin SDK for Node.

Solution 2:

Finally the code should be something like this

 mAuth.signOut();
mAuth.signInWithEmailAndPassword(email,password)
        .addOnCompleteListener(UserList.this, newOnCompleteListener<AuthResult>() {
            @OverridepublicvoidonComplete(@NonNull Task<AuthResult> task) {
                if (!task.isSuccessful()) {
                    mAuth= FirebaseAuth.getInstance(myFirebaseRef.getDatabase().getApp());
                    try{

                        mAuth.signInWithEmailAndPassword(getsPreferences().getString("mailUser",""), getsPreferences().getString("pwd",""))
                                .addOnCompleteListener(UserList.this, newOnCompleteListener<AuthResult>() {
                                    @OverridepublicvoidonComplete(@NonNull Task<AuthResult> task) {

                                    }});
                    }catch(Exception e){

                    }
                }
            }});

Post a Comment for "Reauthenticate User X From An "admin User" To Delete User X"