0

I correctly set up Facebook sign-in with Firebase on my app and now I'd like to make the user able to delete his account. I'd like to re-authenticate the user before deleting the account, but I don't have success.
I followed this example How to re-authenticate a user on Firebase with Google Provider? but the snippet provided by the person who asked the question doesn't help me.
Here is my code

//get the token from the signed in account
val credential = FacebookAuthProvider.getCredential(AccessToken.getCurrentAccessToken().toString())
//reauthenticate the user
user.reauthenticate(credential)
        .addOnCompleteListener { task ->
             if(task.isSuccessful)
                 Toast.makeText(activity, "Authentication successful!!!",Toast.LENGTH_LONG).show()
             else
                 Toast.makeText(activity, "Authentication NOT successful", Toast.LENGTH_LONG).show()
         }

The problem is, when I click the button "Delete" the string "Authentication NOT successful" always appears on screen.

Thank you all in advance.

maurizio
  • 21
  • 6

1 Answers1

1

I had the same problem as you and this is what worked for me

AuthCredential credential = FacebookAuthProvider.getCredential(AccessToken.getCurrentAccessToken().getToken());

    mAuth.getCurrentUser().reauthenticate(credential).addOnCompleteListener(task12 -> {
        if (task12.isSuccessful()) {

            //end onComplete
            mAuth.getCurrentUser().delete()
                    .addOnCompleteListener(task1 -> {
                        if (task1.isSuccessful()) {
                            //YOUR CODE HERE
                        }
                    });
        }else {

        }
    });
Dharman
  • 30,962
  • 25
  • 85
  • 135
Theo.b
  • 68
  • 1
  • 8