I’m working on an Android application that utilizes Firebase for authentication, and I’m facing a challenge. When a user initially creates an account using their email and password, and subsequently signs up with a Google account using the same email address, the original login method seems to be replaced.
if(!userEmail.isEmpty() && !userPassword.isEmpty()) {
authInstance.signInWithEmailAndPassword(userEmail, userPassword).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> authTask) {
if (authTask.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Login successful", Toast.LENGTH_SHORT).show();
} else {
String errorType = ((FirebaseAuthException) authTask.getException()).getErrorCode();
switch (errorType) {
case "ERROR_INVALID_EMAIL":
Toast.makeText(LoginActivity.this, "Email format is invalid.", Toast.LENGTH_LONG).show();
emailField.setError("Email format is invalid.");
emailField.requestFocus();
break;
case "ERROR_USER_NOT_FOUND":
Toast.makeText(LoginActivity.this, "No account found with this email.", Toast.LENGTH_LONG).show();
break;
case "ERROR_WRONG_PASSWORD":
Toast.makeText(LoginActivity.this, "Incorrect password entered.", Toast.LENGTH_LONG).show();
passwordField.setError("Password is wrong");
passwordField.requestFocus();
passwordField.setText("");
break;
case "ERROR_USER_DISABLED":
Toast.makeText(LoginActivity.this, "This account has been disabled.", Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(getApplicationContext(), "Authentication failed: " + authTask.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
});
}
Here’s what’s happening: A user initially registers with their email and password. Later, they sign up using Google with the same email, leading to a wrong password error when they attempt to login using their email and password. This occurs because their credentials have been overwritten by the Google account. I want to show a custom error message like “This email is linked to a Google account. Please log in using Google instead” when this happens. How can I check if an email is already associated with a Google sign-in before trying the email/password login?
This happens because Firebase automatically links accounts with the same email - that’s how it’s supposed to work. When someone signs up with Google using an email that already has a password account, Firebase merges them but uses the newest auth method.
The fetchSignInMethodsForEmail() approach works, but I’d do it differently. Don’t check providers before every login - build it into your error handling instead. When you catch ERROR_WRONG_PASSWORD, that’s when you check sign-in methods and see if Google’s the active provider.
You’ll avoid unnecessary API calls for regular email/password users and help people exactly when they’re stuck. I used this in a banking app where users constantly mixed up their auth methods - cut way down on support tickets about login issues.
Heads up though - fetchSignInMethodsForEmail() got deprecated recently. Now you’re supposed to check provider data after auth attempts fail. The new way’s more secure since it doesn’t reveal which emails are registered.
Firebase has a built-in method to check which providers are linked to an email before you try to authenticate. Use fetchSignInMethodsForEmail() to see if Google is the active provider.
Here’s how:
auth.fetchSignInMethodsForEmail(userEmail).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
List<String> signInMethods = task.getResult().getSignInMethods();
if (signInMethods != null && signInMethods.contains(GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD)) {
Toast.makeText(this, "This email is linked to a Google account. Please log in using Google instead", Toast.LENGTH_LONG).show();
// Show Google sign-in button instead
} else {
// Proceed with email/password authentication
proceedWithEmailPasswordLogin(userEmail, userPassword);
}
}
});
This prevents the wrong password error by checking the provider first.
But here’s the thing - managing auth flows manually gets messy fast. You’ll write tons of conditional logic for different providers, handle edge cases, and maintain error states.
I’ve dealt with similar auth headaches in production apps. What really solved it was automating the entire flow using Latenode. It detects provider conflicts, routes users to the right login method, and sends custom notifications about account linking issues.
The automation handles all Firebase API calls and conditional logic without cluttering your Android code. Way cleaner than managing multiple auth states manually.
This drove me crazy too! Check user.getProviderData() after signin fails. Wrong password? Grab their Firebase user object and loop through the providers. If you see ‘google.com’ but they’re trying email/password, show your custom message. Way simpler than fetchSignInMethods and won’t break when Firebase updates their API.
I skip the upfront provider checks and handle this during auth failures instead. When Firebase throws an email/password error, I immediately check the user’s provider data to see if they should be using Google. Here’s the trick: Firebase keeps provider info even after account linking. In your catch block for auth errors, add a provider check for wrong password scenarios. You’re only making extra API calls when there’s actually a problem, not every single login. I did something similar for a corporate app where users constantly mixed up their login methods. Instead of checking providers upfront, I built detection right into the error flow. Wrong password? System instantly checks if Google’s their primary provider and redirects them. This works better because most people remember how they log in. You only burn resources on provider detection when someone’s actually stuck. Plus the UX feels smoother since successful logins don’t get slowed down by unnecessary provider checks.