I am using this code:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.updateEmail("[email protected]")
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User email address updated.");
}
}
});
But still I am not able to update user Email ID for logged in person. Other things working fine but not this.
Open your project in the Firebase console. Go to the Email Templates page in the Auth section. In any of the Email Types entries, click the pencil icon to edit the email template. Click customize action URL, and specify the URL to your custom email action handler.
You will also need to reauthenticate the login prior to calling this as Firebase requires a fresh authentication to perform certain account functions such as deleting the account, changing the email or the password.
You need to re-authenticate your user. As according to documentation changing primary email address is a sensitive action.
Re-Authentication :
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
// Get auth credentials from the user for re-authentication
AuthCredential credential = EmailAuthProvider
.getCredential("[email protected]", "password1234"); // Current Login Credentials \\
// 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) {
Log.d(TAG, "User re-authenticated.");
//Now change your email address \\
//----------------Code for Changing Email Address----------\\
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.updateEmail("[email protected]")
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User email address updated.");
}
}
});
//----------------------------------------------------------\\
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With