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
- Store the Firebase apiKey and config as CI secrets.
- Expose them in the step env with the prefix your bundler needs.
- 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
Firebase Auth emulator "ECONNREFUSED" in CIFix Firebase Auth emulator "connect ECONNREFUSED 127.0.0.1:9099" in CI - the tests ran before the emulator fi…
Cognito "InvalidParameterException" on InitiateAuth in CIFix Cognito "InvalidParameterException" in CI - the auth flow or required auth parameters do not match how th…
JWT "jwt malformed" in CI token verificationFix "JsonWebTokenError: jwt malformed" in CI - the value passed to the JWT verifier is not a well-formed thre…