This error occurs when a user tries to create an account with an email that already exists in your Firebase project. Learn how to detect this error, prompt users to log in instead, and check for existing accounts before sign-up.
The "auth/email-already-in-use" error is Firebase's way of preventing duplicate accounts with the same email address. When a user attempts to create a new account using `createUserWithEmailAndPassword()` with an email that is already registered in your Firebase authentication database, Firebase blocks the operation and throws this error. This is a protective measure to maintain data integrity and prevent confusion from multiple accounts sharing the same email.
When calling createUserWithEmailAndPassword(), wrap it in a try-catch block or add a .catch() handler to detect the error:
import { createUserWithEmailAndPassword } from 'firebase/auth';
createuserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
console.log('User created:', userCredential.user);
})
.catch((error) => {
if (error.code === 'auth/email-already-in-use') {
console.log('Email already in use!');
}
});Show the user that the email is already registered and offer them options:
if (error.code === 'auth/email-already-in-use') {
setErrorMessage('This email is already registered. Please sign in instead.');
// Optionally show a button to redirect to login page
}Use fetchSignInMethodsForEmail() to check if an email exists BEFORE attempting to create the account:
import { fetchSignInMethodsForEmail } from 'firebase/auth';
async function handleSignUp(email, password) {
try {
const methods = await fetchSignInMethodsForEmail(auth, email);
if (methods.length > 0) {
setErrorMessage('This email is already registered.');
return;
}
// Safe to proceed with account creation
await createUserWithEmailAndPassword(auth, email, password);
} catch (error) {
console.error('Sign-up error:', error.message);
}
}When the error occurs, give users an easy way to sign in instead:
if (error.code === 'auth/email-already-in-use') {
return (
<div>
<p>This email is already registered.</p>
<button onClick={() => navigateTo('/login')}>Sign In</button>
<p>or try signing up with a different email</p>
</div>
);
}If a user registered with Google Sign-In but tries to sign up with email/password using the same email, you'll get this error. Handle this by offering to link accounts:
if (error.code === 'auth/email-already-in-use') {
// User can sign in with the existing method (e.g., Google)
setErrorMessage(
'This email is already associated with another sign-in method. Please sign in with that method.'
);
}Consider enabling email enumeration protection in your Firebase Console security settings. This prevents bad actors from discovering which emails are registered by catching all errors with a generic message instead of revealing whether an email exists. However, this will make your app's error handling less specific. For test environments, use different email addresses for each test run (e.g., test-${Date.now()}@example.com) or delete test users between runs. Some SDKs may return email-already-in-use when attempting to link credentials with linkWithCredential() - ensure your app logic doesn't assume linking with the same email will always succeed.
Callable Functions: INTERNAL - Unhandled exception
How to fix "Callable Functions: INTERNAL - Unhandled exception" in Firebase
messaging/UNSPECIFIED_ERROR: No additional information available
How to fix "messaging/UNSPECIFIED_ERROR: No additional information available" in Firebase Cloud Messaging
auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options
How to fix "auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options" in Firebase
App Check: reCAPTCHA Score Too Low
App Check reCAPTCHA Score Too Low
storage/invalid-url: Invalid URL format for Cloud Storage reference
How to fix invalid URL format in Firebase Cloud Storage