Firebase auth/invalid-api-key Error

Share
Ongoing Web Updated November 13, 2026Based on 4 user reportsHow we research

Quick answer

Firebase got an empty or malformed apiKey in initializeApp. In framework apps this is nearly always an environment variable that is undefined at build or run time, for example missing the NEXT_PUBLIC_ prefix or not set in the hosting platform.

Most likely fix: Check the key actually reaches the app

How to fix it

Try these in order — the most common fix is first.

  1. 1. Check the key actually reaches the app

    1. console.log(process.env.NEXT_PUBLIC_FIREBASE_API_KEY) (or import.meta.env for Vite) and confirm it is not undefined
    2. Use the exact prefix your framework exposes to the browser
    Did this fix it?
  2. 2. Restart and rebuild

    1. Stop the dev server and start it again after editing .env
    2. Redeploy after changing host env vars; build-time variables are baked into the bundle
    Did this fix it?
  3. 3. Set variables on your host

    1. Add every firebaseConfig value in your hosting dashboard's environment settings
    2. Remove quotes, trailing spaces and stray parentheses
    Did this fix it?
  4. 4. Copy a fresh config

    1. Firebase console > Project settings > Your apps > SDK setup and configuration
    2. Paste the config again and compare apiKey
    Did this fix it?

Symptoms

Uncaught FirebaseError: Firebase: Error (auth/invalid-api-key), often only on the deployed site or after a rebuild.

Why it happens

  • Env variable lacks the framework's public prefix (NEXT_PUBLIC_, VITE_)
  • Dev server not restarted after editing .env
  • Variables set locally but not in Vercel, Netlify or Cloudflare settings
  • Stray characters or quotes in the key value
  • Wrong casing of the variable name

This guide also covers

  • auth/invalid-api-key
  • firebase invalid api key next.js
  • firebase api key undefined

Still not working?

If Firebase keeps failing, you're not alone. See every Firebase problem users report or the alternatives people switch to.

Have an app idea? Our small team builds any software: web and mobile apps, games, desktop, AI tools. Price agreed together.

Talk to us
Fixed it? Share this guide

The same problem in other apps

All not loading, error messages & connection guides →

Other Firebase errors

All 10 Firebase errors and fixes →