[firebase_auth_web]: Make the Auth emulator persistence from #18926 configurable instead of hard-gated on kDebugMode

未关闭
#18,992 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

@SelaseKay 已经在做这个了。

开始于 2026年11月25日。

  • #19013 来自 @SelaseKay —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
62/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
dart, firebase, flutter

调研方向

Start from the two kDebugMode gates in packages/firebase_auth/firebase_auth_web/lib/firebase_auth_web.dart (restore on plugin init ~L60-75, remember-after-connect ~L565-600) and read the #18926 diff; the isAuthEmulatorDebugHost loopback check stays as is. Because the origin is reapplied inside Firebase.initializeApp, the flag must be readable before init: decide between a static on FirebaseAuth in the firebase_auth package (threaded through the platform interface) or a bool.fromEnvironment define, then have the web implementation read it. Done means the default still equals kDebugMode, profile builds can opt in, and existing web auth tests plus a new gate test pass.

由索引模型根据 Issue 内容生成。

描述

Needs Attention platform: web plugin: auth type: enhancement
Which plugins/Platforms are affected?

Auth on Web

TL;DR

The fix from #18926 that keeps the Auth emulator across restarts is hard-gated on kDebugMode, so profile builds can't use it; please make that gate a setting, with a default of kDebugMode to keep existing behavior.

Description

#18926 (fixing #18888) keeps the Auth emulator origin across reloads and browser restarts, so a persisted user is never restored against production before useAuthEmulator runs. All of it is hard-gated on kDebugMode:

Request: replace those kDebugMode checks with a single setting whose default is kDebugMode, so nothing changes unless an app opts in. Because the origin is reapplied inside Firebase.initializeApp, the setting has to be readable before init, e.g. either:

// set before Firebase.initializeApp
FirebaseAuth.persistWebEmulatorOrigin = true; // default: kDebugMode

or a compile-time define:

const persist = bool.fromEnvironment(
  'FIREBASE_AUTH_PERSIST_EMULATOR',
  defaultValue: kDebugMode,
);

The existing loopback-host check (isAuthEmulatorDebugHost) would stay as it is.

Why is this important?

Profile builds are a normal way to test against the emulators. Debug can be too slow for canvas-heavy apps. In profile mode today:

  1. The persisted (anonymous) emulator user is restored from IndexedDB on startup.
  2. If its ID token is older than an hour, it is refreshed against securetoken.googleapis.com, which is production. With a referrer-restricted key, that fails with auth/requests-from-referer-http://localhost:<port>/-are-blocked.
  3. The later useAuthEmulator call fails with emulator-config-failed, silently outside debug, so Auth stays on production for the whole session, and Firestore on its emulator reports "client is offline".

The only way out is clearing site storage, which deletes the anonymous user and its emulator data every time.

Additional context and comments

firebase_core 5.2.0, firebase_auth 7.1.0, firebase_auth_web 6.4.0.
Related: #11233, #11534, #18689, #18888, #18926.

主要语言
Dart
星标
9.3k
派生
4.1k
平均合并
4 天 17 小时
30 天内合并 PR
49

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/flutterfire 的其他 Issue

查看 firebase/flutterfire 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。