且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Android应用程序中删除Firebase用户?

更新时间:2023-12-05 17:24:34

As per the Firebase documentation can user delete() method to remove user from the Firebase

Before remove the user please reAuthenticate the user.

Sample code

     final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

        // Get auth credentials from the user for re-authentication. The example below shows
        // email and password credentials but there are multiple possible providers,
        // such as GoogleAuthProvider or FacebookAuthProvider.
        AuthCredential credential = EmailAuthProvider
                .getCredential("user@example.com", "password1234");

        // Prompt the user to re-provide their sign-in credentials
        user.reauthenticate(credential)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
           user.delete()
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "User account deleted.");
                    }
                }
            });

   }
});

For more details : https://firebase.google.com/docs/auth/android/manage-users#re-authenticate_a_user

If you want to user re Authentication with other singin provider only need to change the Provider for GoogleAuthProvider below is the sample code

GoogleAuthProvider.getCredential(googleIdToken,null);

相关阅读

推荐文章