alon
alon

Reputation: 11

How to change the email and password in Firebase Authentication?

I saw few similar questions but any of the solutions didn't help me.So basically i want to change my email and password in authentication when the user is already logged.

I tried to use the methods updateEmail/password but its didn't changed anything. Here example of code that i wrote:

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

user.updateEmail(NewEmail)
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    Log.d(TAG, "User email address updated.");
                }
            }
        }); 

(the variable 'NewEmail' its the email that the user decide to change and then its should to change the email in authentication) The problem is in that case that its show me line on the 'updateEmail' like its tell me that the method is not work of something like that,and all what i tried didn't worked. And about how to change the password i tried the same way(the code from the site of firebase authentication) it was without the line on 'updatepassword' like in the email method,but its didn't changed the password and when the user need to log in again its required the previous password(the first password that the user registered with). If someone has any solution please help me!Thanks:)

Upvotes: 0

Views: 71

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599491

If the task is not successful, there's an exception in there that explain why it failed - but your code is not handling that case. To figure out the root cause of the problem:

public void onComplete(@NonNull Task<Void> task) {
    if (task.isSuccessful()) {
        Log.d(TAG, "User email address updated.");
    }
    else {
        Log.e(TAG, "User email address update failed", task.getException());
    }
}

Upvotes: 1

Related Questions