How to fix auth/invalid-email in Firebase

FirebaseBEGINNERLOWUpdated Dec 22, 2025ยท 244 views

The auth/invalid-email error occurs when an email address is not properly formatted or contains invalid characters. Fix it by validating and trimming email input before passing it to Firebase authentication methods.

Quick fix

Fixes auth/invalid-email

const email = userInput.trim().toLowerCase();

try {
  await firebase.auth().signInWithEmailAndPassword(email, password);
} catch (error) {
  if (error.code === 'auth/invalid-email') {
    console.error('Invalid email format');
  }
}
  1. Trim and validate email input before authentication
  2. Check that you're passing string values, not objects
  3. Implement proper error handling for invalid email
  4. Add client-side email validation before Firebase calls
firebase โ€” error
const email = userInput.trim().toLowerCase();
try {
await firebase.auth().signInWithEmailAndPassword(email, password);
} catch (error) {
if (error.code === 'auth/invalid-email') {
console.error('Invalid email format');
}
}
auth/invalid-email

What this error means

Firebase throws this error when you attempt to authenticate using an email address that does not conform to the standard email format. This is a client-side validation error that Firebase enforces to ensure only valid email addresses can be used for authentication. The error is triggered by the Firebase SDK when creating a user account, signing in, or performing password resets with a malformed email address.

Typical symptoms

  • Authentication fails with error code auth/invalid-email
  • Login attempts rejected when email appears valid
  • User registration fails silently or shows generic validation error
  • Email validation works locally but fails in production
  • Whitespace appears in email fields without user awareness

Common causes

  1. Email address missing the @ symbol (e.g., "userexample.com")
  2. Email contains invalid special characters or spaces
  3. Whitespace characters (spaces, tabs, newlines) prepended or appended to email
  4. Passing an object instead of string value to authentication method
  5. Email input not trimmed before sending to Firebase
  6. Email input in uppercase but Firebase rejects certain formats

How to fix "auth/invalid-email"

1Trim and validate email input before authentication

The most common cause is whitespace in the email field. Always clean user input before sending to Firebase:

JavaScript/Web SDK:

javascript
const email = userInput.trim().toLowerCase();

try {
  await firebase.auth().signInWithEmailAndPassword(email, password);
} catch (error) {
  if (error.code === 'auth/invalid-email') {
    console.error('Invalid email format');
  }
}

TypeScript with Firebase Admin SDK:

typescript
const email = userInput.trim().toLowerCase();

try {
  const user = await admin.auth().getUserByEmail(email);
} catch (error) {
  if (error.code === 'auth-user-not-found') {
    // Different error when using Admin SDK
  }
}

iOS (Swift):

swift
let email = emailInput.trimmingCharacters(in: .whitespaces).lowercased()

Auth.auth().signIn(withEmail: email, password: password) { result, error in
  if let error = error as? NSError {
    if error.code == AuthErrorCode.invalidEmail.rawValue {
      print('Invalid email format')
    }
  }
}

Android (Kotlin):

kotlin
val email = emailInput.trim().toLowerCase()

FirebaseAuth.getInstance().signInWithEmailAndPassword(email, password)

.addOnFailureListener { exception ->

javascript
if (exception is FirebaseAuthInvalidUserException) {
      Log.e('Auth', 'Invalid email format')
    }
  }
2Check that you're passing string values, not objects

A common mistake when managing state is passing the entire state object instead of the string value:

WRONG - passing the entire email object:

javascript
const state = { email: { value: 'user@example.com' } };
await firebase.auth().signInWithEmailAndPassword(state.email, password);
// Error: auth/invalid-email

CORRECT - passing only the string value:

javascript
await firebase.auth().signInWithEmailAndPassword(state.email.value, password);

WRONG with React hooks:

javascript
const [email, setEmail] = useState({});
await firebase.auth().signInWithEmailAndPassword(email, password);

CORRECT with React hooks:

javascript
const [email, setEmail] = useState('');
await firebase.auth().signInWithEmailAndPassword(email, password);
3Implement proper error handling for invalid email

Add specific error handling to distinguish invalid email from other authentication errors:

javascript
async function handleSignIn(email, password) {
  try {
    const email = email.trim().toLowerCase();
    await firebase.auth().signInWithEmailAndPassword(email, password);
  } catch (error) {
    if (error.code === 'auth/invalid-email') {
      // Email format is wrong
      showError('Please enter a valid email address (e.g., user@example.com)');
    } else if (error.code === 'auth/user-not-found') {
      // Email format is valid but account doesn't exist
      showError('No account found with this email');
    } else if (error.code === 'auth/wrong-password') {
      // User exists but password is incorrect
      showError('Incorrect password');
    } else {
      showError('Authentication failed: ' + error.message);
    }
  }
}
4Add client-side email validation before Firebase calls

Validate email format locally before making Firebase requests to provide faster feedback:

Simple regex pattern for email validation:

javascript
function isValidEmail(email) {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return emailRegex.test(email);
}

async function signInUser(emailInput, password) {
  const email = emailInput.trim().toLowerCase();

  // Client-side validation first
  if (!isValidEmail(email)) {
    showError('Invalid email format');
    return;
  }

  try {
    await firebase.auth().signInWithEmailAndPassword(email, password);
  } catch (error) {
    handleAuthError(error);
  }
}

Using a library like email-validator:

javascript
import validator from 'email-validator';

const email = userInput.trim().toLowerCase();
if (!validator.validate(email)) {
  showError('Invalid email format');
  return;
}

Advanced notes

Firebase has different validation rules between SDKs. When creating a user with the Admin SDK, invalid email might be accepted at account creation but rejected during sign-in, creating an inconsistency. Some special characters (like accented letters) may pass client validation but fail server validation. For maximum compatibility, stick to standard ASCII email formats. If you're using custom claims or linking providers, ensure the email is validated before updating user metadata. React Native Firebase and Flutter SDKs expose errors via FirebaseAuthException with the error.code property - use try-catch blocks with on FirebaseAuthException to handle this gracefully.

Frequently asked questions

What does "auth/invalid-email" mean?
Firebase throws this error when you attempt to authenticate using an email address that does not conform to the standard email format. This is a client-side validation error that Firebase enforces to ensure only valid email addresses can be used for authentication. The error is triggered by the Firebase SDK when creating a user account, signing in, or performing password resets with a malformed email address.
How do I fix "auth/invalid-email"?
The auth/invalid-email error occurs when an email address is not properly formatted or contains invalid characters. Fix it by validating and trimming email input before passing it to Firebase authentication methods.
What causes "auth/invalid-email"?
Email address missing the @ symbol (e.g., "userexample.com") Email contains invalid special characters or spaces Whitespace characters (spaces, tabs, newlines) prepended or appended to email
Is the "auth/invalid-email" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading