Reauthenticate user x from an “admin user” to delete user x

前端 未结 2 507
深忆病人
深忆病人 2021-01-25 17:38

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 c

相关标签:
2条回答
  • 2021-01-25 17:58

    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.

    0 讨论(0)
  • 2021-01-25 18:15

    Finally the code should be something like this

     mAuth.signOut();
    mAuth.signInWithEmailAndPassword(email,password)
            .addOnCompleteListener(UserList.this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@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, new OnCompleteListener<AuthResult>() {
                                        @Override
                                        public void onComplete(@NonNull Task<AuthResult> task) {
    
                                        }});
                        }catch(Exception e){
    
                        }
                    }
                }});
    
    0 讨论(0)
提交回复
热议问题