Skip to content
Latchkey

Firebase Auth "auth/invalid-api-key" in CI

The Firebase Web SDK rejected initialization because the apiKey in the config was missing or empty. In CI this almost always means the env var holding the Firebase config was not injected.

What this error means

Test setup fails with "FirebaseError: Firebase: Error (auth/invalid-api-key)." The apiKey passed to initializeApp is undefined because the CI env var is unset.

Firebase Auth
FirebaseError: Firebase: Error (auth/invalid-api-key).
    at createErrorInternal (/app/node_modules/@firebase/auth/dist/index.js:...)

Common causes

The Firebase config env var is unset in CI

The apiKey comes from an env var that is not injected into the job, so it is undefined at initializeApp.

A build that stripped the client env

A bundler that requires a specific prefix (e.g. VITE_/NEXT_PUBLIC_) drops the key if the var is not named accordingly.

How to fix it

Inject the Firebase config into the job

  1. Store the Firebase apiKey and config as CI secrets.
  2. Expose them in the step env with the prefix your bundler needs.
  3. Assert apiKey is non-empty before initializeApp.
.github/workflows/ci.yml
env:
  VITE_FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }}

Point tests at the Auth emulator

For CI, use the Firebase Auth emulator so real API keys are not required for local auth tests.

How to prevent it

  • Inject Firebase config via CI secrets with the correct bundler prefix.
  • Assert apiKey is present before initializing the app.
  • Prefer the Auth emulator for CI so no live key is needed.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →