androidfirebasefirebase-authenticationfirebaseuigoogle-account

Firebase authenticate with both email and Google account


I am using Firebase UI to implement user authentication on my Android app but I'm facing a problem. Here is the scenario:

  1. User creates an account using their email address
  2. User signs out of that account
  3. The same user tries to sign in with their Google account, which happens to be the same email address that they used to create an account with email address is step 1
  4. User successfully signs in and can see the data from the account (which are the same as the account on step 1
  5. User signs out
  6. User tries to sign in with email address
  7. User gets unknown error and cannot sign in with email address. Everything works fine with Google account, but sign in with email is not working anymore.

I tried to use web client to find the actual error, when trying to sign in using email address I get the following error:

{
 "code":"auth/wrong-password",
 "message":"The password is invalid or the user does not have a password."
}

Solution

  • This is happening because when the user signs in the second time, with a Google account, it overrides the data in the Firebase account. This means that Google credentials remain the default ones. This is happening for an obvious reason, a Google account is a trusted source and that's why we have this behavior.

    To solve your problem, you need to link those 2 accounts in a single one, based on that email address.