Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

FIREBASE_AUTH_EMULATOR_HOST affects all initailized apps, unlike other emulator env var

Abierto
#2,948 3 comentarios 1 reacción 1 asignado Ver en GitHub

@lahirumaramba ya está trabajando en esto.

Desde el 7/7/2025.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

help wanted type: feature request

When initializing Firebase Admin to use the emulator, it's required to set the env var FIREBASE_AUTH_EMULATOR_HOST prior to calling initializeApp. This works fine, however, the way this value is used internally has a significant problem: The env var is consulted every time an API call is made. This makes it impossible to have two initialized apps in one process (for example, one pointing to the cloud project, and the other to the emulator.

The relevant code in this repo:

https://github.com/firebase/firebase-admin-node/blob/26b884f70300ef8e3213dfbbd72351ce7f68c695/src/auth/auth-api-request.ts#L2313-L2323

useEmulator is used whenever an API call is made, which affects all applications. So, one application cannot simply set the env var while another unsets it. What's especially confusing about this behavior is that the other env vars don't work like this at all. I can set the var only when needed prior to init, then unset it later to initialize another app.

For example, this works for Firestore and Storage, but not for Auth:

// Initializing an app for remote cloud project access

export const remoteApp = initializeApp(options, "remote")
export const remoteAuth = getAuth(remoteApp)
export const remoteFirestore = getFirestore(remoteApp)
export const remoteStorage = getStorage(remoteApp)

// Initializing a second app for local emulator access

process.env.FIREBASE_AUTH_EMULATOR_HOST="127.0.0.1:9099"
process.env.FIRESTORE_EMULATOR_HOST = "localhost:8080"
process.env.FIREBASE_STORAGE_EMULATOR_HOST = "127.0.0.1:9199"
export const localApp = initializeApp(options, "local")
export const localAuth = getAuth(localApp)
export const localFirestore = getFirestore(localApp)
export const localStorage = getStorage(localApp)
delete process.env.FIREBASE_AUTH_EMULATOR_HOST
delete process.env.FIRESTORE_EMULATOR_HOST
delete process.env.FIREBASE_STORAGE_EMULATOR_HOST

Deleting FIREBASE_AUTH_EMULATOR_HOST here causes the app for the local emulator to instead use the remote service. However, not deleting it causes the remote app to use the local emulator. Again, Firestore and Storage don't have this problem.

As of now, I can't find a way to use emulator auth and remote auth in the same project. It would be great if the admin SDK would take the value of FIREBASE_AUTH_EMULATOR_HOST just once at the time of init, store it, and use it later so that var can be deleted afterward. Or even better, initializeApp could directly take emulator configs as input instead of relying solely on env vars that affect the entire process globally.

See also this comment in another issue: https://github.com/firebase/firebase-admin-node/issues/776#issuecomment-1781154086

Lenguaje dominante
TypeScript
Estrellas
1.7k
Forks
419
Merge medio
4 d 20 h
PR fusionados (30 d)
16

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de firebase/firebase-admin-node

Todos los issues de firebase/firebase-admin-node

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.