skip to Main Content

I want the user to be able to update their email address from within the app. I wrote the following code to update email in Firebase Authentication.

val user = firebaseUser.currentUser!!
val credential = EmailAuthProvider
    .getCredential(currentEmail, currentPassword)

user.reauthenticate(credential)
    .addOnCompleteListener {
        firebaseUser.currentUser?.updateEmail(newEmail)
            ?.addOnCompleteListener { updateEmailResult ->
                if (updateEmailResult.isSuccessful) {
                    val userRef = firestore.collection("users").document(userId)
                    userRef
                        .update("email", newEmail)
                        .addOnSuccessListener {
                            onSuccess()
                        }
                        .addOnFailureListener { e ->
                            onError(e)
                        }
                } else {
                    val exception = updateEmailResult.exception
                    if (exception != null) {
                    }
                }
            }

However, when I debug if (exception != null) works.
The following message is returned:

The given sign-in provider is disabled for this Firebase project. Enable it in the Firebase console, under the sign-in method tab of the Auth section. [ Please verify the new email before changing email.]

2

Answers


  1. You are unable to reauthenticate the user because the option to authenticate the user with email and password is not enabled. To achieve this, you have to open the Firebase Console, go to the Authentication section in your project, and inside the Sign-in method please enable Email/Password provider. In the end, it should look like this:

    enter image description here

    As the message says, it is also recommended to to verify the new email before changing the email.

    Login or Signup to reply.
  2. The error message you’re encountering suggests that the sign-in provider for email authentication might be disabled in your Firebase project. Additionally, it mentions verifying the new email before changing it. Here’s how you can address these issues:

    1. Enable Email/Password Sign-in Provider:

    -> Go to the Firebase Console (https://console.firebase.google.com/).

    -> Select your project.

    -> In the left sidebar, click on "Authentication."

    -> Go to the "Sign-in method" tab.

    -> Make sure that "Email/Password" is enabled as a sign-in provider. If it’s not enabled, enable it.

    2. Verify New Email:

    -> Firebase may require you to verify the new email address before allowing an update. This is often a security measure.

    -> After enabling the email/password sign-in provider, ensure that the email verification settings are configured correctly in your Firebase project.

    -> In your code, you should consider sending a verification email to the new email address and prompting the user to verify it. You can use the following code to send a verification email:

    firebaseUser.currentUser?.sendEmailVerification()
        ?.addOnCompleteListener { emailVerificationResult ->
            if (emailVerificationResult.isSuccessful) {
                // Email verification sent, prompt the user to verify their new email.
            } else {
                // Handle the case where email verification sending failed.
            }
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search