How to fix auth/account-exists-with-different-credential in Firebase

FirebaseINTERMEDIATEMEDIUMUpdated Dec 22, 2025ยท 214 views

This error occurs when a user tries to sign in with a provider (like Google) using an email already linked to another provider (like Facebook). Enable account linking or prompt users to sign in with their existing provider first.

Quick fix

Fixes auth/account-exists-with-different-credential

import { signInWithRedirect, getRedirectResult, GoogleAuthProvider } from 'firebase/auth';

try {
  const result = await getRedirectResult(auth);
  // Sign in successful
} catch (error) {
  if (error.code === 'auth/account-exists-with-different-credential') {
    // Extract the pending credential from the error
    const pendingCredential = GoogleAuthProvider.credentialFromError(error);

    // Get the email to display to user
    const email = error.customData?.email;

    // Prompt user to sign in with their existing provider
    console.log('Account exists with different credential for:', email);
    // Store pendingCredential for linking in next step
  }
}
  1. Check Firebase Console settings
  2. Catch the error and extract credentials
  3. Prompt user to sign in with existing provider
  4. Link the new provider to the existing account
firebase โ€” error
import { signInWithRedirect, getRedirectResult, GoogleAuthProvider } from 'firebase/auth';
try {
const result = await getRedirectResult(auth);
// Sign in successful
} catch (error) {
if (error.code === 'auth/account-exists-with-different-credential') {
// Extract the pending credential from the error
const pendingCredential = GoogleAuthProvider.credentialFromError(error);
// Get the email to display to user
const email = error.customData?.email;
// Prompt user to sign in with their existing provider
console.log('Account exists with different credential for:', email);
// Store pendingCredential for linking in next step
}
}
auth/account-exists-with-different-credential

What this error means

The "account-exists-with-different-credential" error is thrown by Firebase Authentication when you have "Link accounts that use the same email" enabled in your Firebase console, and a user attempts to authenticate with an OAuth provider (Google, Facebook, GitHub, etc.) using an email address that is already associated with a different authentication provider in your project. Firebase uses email addresses as the unique identifier to link accounts across multiple providers, so this conflict occurs when the same email tries to use different providers.

Typical symptoms

  • Sign-in process fails when users attempt to use a social provider (Google, Facebook, GitHub) with an email already linked to another provider
  • Users see an error dialog or redirect without successful authentication
  • Account linking flows do not automatically resolve the conflict
  • Mobile or web apps using signInWithRedirect or signInWithPopup throw unhandled errors

Common causes

  1. "Link accounts that use the same email" setting is enabled in Firebase Authentication settings (most common)
  2. User previously signed up with one provider (e.g., Facebook) and now tries to sign in with another provider using the same email (e.g., Google)
  3. Multi-provider authentication is implemented without proper account linking logic in the app
  4. Email-based authentication (password) is mixed with OAuth providers for the same user
  5. Older Firebase versions or libraries with inconsistent account linking behavior across different OAuth providers

How to fix "auth/account-exists-with-different-credential"

1Check Firebase Console settings

First, verify your account linking configuration in Firebase Console:

1. Go to Firebase Console > Authentication > Settings
2. In the "User account linking" section, check your current setting:
- If "Link accounts that use the same email address" is enabled, this error can occur
- If "Create multiple accounts for each identity provider" is enabled, this error should not appear

Note: The setting determines how Firebase handles email conflicts. Enable "Link accounts" only if you want to enforce one account per email across all providers.

2Catch the error and extract credentials

In your authentication code, add error handling for this specific error code and extract the AuthCredential from the error object:

For Firebase JS SDK v9+:

javascript
import { signInWithRedirect, getRedirectResult, GoogleAuthProvider } from 'firebase/auth';

try {
  const result = await getRedirectResult(auth);
  // Sign in successful
} catch (error) {
  if (error.code === 'auth/account-exists-with-different-credential') {
    // Extract the pending credential from the error
    const pendingCredential = GoogleAuthProvider.credentialFromError(error);

    // Get the email to display to user
    const email = error.customData?.email;

    // Prompt user to sign in with their existing provider
    console.log('Account exists with different credential for:', email);
    // Store pendingCredential for linking in next step
  }
}

For Flutter:

dart
try {
  final result = await FirebaseAuth.instance.signInWithPopup(googleProvider);
} on FirebaseAuthException catch (e) {
  if (e.code == 'account-exists-with-different-credential') {
    // Get the email associated with the account
    final email = e.email;

    // Get list of sign-in methods for this email
    final methods = await FirebaseAuth.instance.fetchSignInMethodsForEmail(email!);
    print('Sign-in methods available: $methods');
  }
}
3Prompt user to sign in with existing provider

Display a message to the user explaining the situation and guiding them to sign in with their existing provider:

javascript
const email = error.customData?.email;
const methods = await auth.fetchSignInMethodsForEmail(email);

// Example: methods might be ['facebook.com', 'password']
alert(`This email is already registered with ${methods.join(', ')}. Please sign in with that provider first.`);

// Redirect user to sign in with their existing provider
// Example: sign in with Facebook if that's their existing provider
const result = await signInWithPopup(auth, facebookProvider);

,

Store the pending credential (from step 2) so you can link it after the user signs in with their existing provider.

4Link the new provider to the existing account

After the user signs in with their existing provider, link the new provider using the stored pending credential:

For Firebase JS SDK v9+:

javascript
// After user successfully signs in with their existing provider
try {
  // Link the pending credential (from the original sign-in attempt) to the current user
  await linkWithCredential(auth.currentUser, pendingCredential);
  console.log('Account linked successfully!');
} catch (error) {
  console.error('Failed to link accounts:', error);
}

For Flutter:

dart
try {
  // After signing in with existing provider, get user and link new provider
  final facebookCredential = await FirebaseAuth.instance.signInWithPopup(facebookProvider);
  await auth.currentUser?.linkWithCredential(googleAuthCredential);
  print('Accounts linked!');
} catch (e) {
  print('Link failed: ${e.message}');
}
5Alternative: Disable account linking (simple approach)

If you don't need to merge accounts across providers, you can simply disable account linking:

1. Go to Firebase Console > Authentication > Settings
2. Set "User account linking" to "Create multiple accounts for each identity provider"
3. Redeploy your app

With this setting, users can create separate accounts for each provider using the same email address. This eliminates the "account-exists-with-different-credential" error but prevents automatic account merging.

Pros: Simpler implementation, no custom linking logic needed
Cons: Users may accumulate multiple accounts with the same email

Advanced notes

Known Issues and Workarounds:

1. Missing email in error object (Flutter, React Native): Some versions of Firebase SDKs don't include the email in the error object. Workaround: Use fetchSignInMethodsForEmail() with the email the user just tried to sign in with.

2. Inconsistent behavior between providers: Some OAuth flows (particularly signInWithRedirect) may not throw this error consistently depending on which provider is used first. Always implement proper error handling.

3. credential property undefined (v9 SDK): In some Firebase v9 implementations, error.credential is undefined. Use GoogleAuthProvider.credentialFromError(error) (or the appropriate provider class) instead.

4. FirebaseUI compatibility: If using FirebaseUI, ensure it's updated to handle account linking properly. Older versions may not properly resolve this error.

5. Testing locally: This error only occurs with "Link accounts" setting enabled. Test your flow both with and without account linking to ensure proper behavior.

Frequently asked questions

What does "auth/account-exists-with-different-credential" mean?
) using an email address that is already associated with a different authentication provider in your project. Firebase uses email addresses as the unique identifier to link accounts across multiple providers, so this conflict occurs when the same email tries to use different providers.
How do I fix "auth/account-exists-with-different-credential"?
This error occurs when a user tries to sign in with a provider (like Google) using an email already linked to another provider (like Facebook). Enable account linking or prompt users to sign in with their existing provider first.
What causes "auth/account-exists-with-different-credential"?
"Link accounts that use the same email" setting is enabled in Firebase Authentication settings (most common) User previously signed up with one provider (e.g., Facebook) and now tries to sign in with another provider using the same email (e.g., Google) Multi-provider authentication is implemented without proper account linking logic in the app
Is the "auth/account-exists-with-different-credential" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading