0

I need to re-authenticate the user in order to delete his profile. I've already seen this answer How to re-authenticate a user on Firebase with Google Provider? but it doesn't work for me. In fact this code below eliminates correctly the user only if he has signed in recently. So in my code seems that user.reauthenticate(credential) doesn't work.

public void OnDeleteProfile(View view){
    new AlertDialog.Builder(this)
    .setPositiveButton("Delete", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(getApplicationContext());
            AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(),null);
            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) {
                        }
                    });

               }
            });

        }
    })
    .setIcon(android.R.drawable.ic_dialog_alert)
    .show();
}
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Fabio
  • 13
  • 3
  • Well, you could store the id token when you sign in inside shared preferences, but I won't recommend that. – Gaurav Mall Aug 15 '19 at 16:12
  • Why don't you recommend that? Is there another solution? – Fabio Aug 16 '19 at 14:12
  • I don't recommend that because hackers can read anybody's shared preferences, get their id token and sign in stealing their account. The original solution is the one you provided. Although it seems that it doesn't work for you. – Gaurav Mall Aug 16 '19 at 16:20

0 Answers0