FIREBASE_AUTH_EMULATOR_HOST affects all initailized apps, unlike other emulator env var
@lahirumaramba 已经在做这个了。
开始于 2025年7月7日。
评估
这个 Issue 还没有评估数据。
描述
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:
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
- 主要语言
- TypeScript
- 星标
- 1.7k
- 派生
- 419
- 平均合并
- 4 天 20 小时
- 30 天内合并 PR
- 16
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/firebase-admin-node 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 35/100
firebase/firebase-admin-node#3234 ·
-
firebase/firebase-admin-node#3221 · 3 条评论 · 已指派 1 人 ·
-
api: messaging
难度 3/5 1-2 天 新手友好度 70/100
firebase/firebase-admin-node#3215 ·
-
api: messaging
难度 5/5 一周以上 新手友好度 28/100
firebase/firebase-admin-node#3214 ·
-
api: firestore type: feature request
firebase/firebase-admin-node#3183 · 1 条评论 · 已指派 1 人 ·
查看 firebase/firebase-admin-node 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
mksglu/context-mode#1200 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
难度 2/5 1-3 小时 新手友好度 75/100
anthropics/claude-code#96687 ·
-
good first issue
难度 1/5 1 小时以内 新手友好度 95/100
AOSSIE-Org/DebateAI#582 · 2 条评论 ·