Conversation
… auth state is an error When the JS SDK's first onAuthStateChanged callback fires with an error (e.g. IndexedDB _openDb rejection at page load), onWaitInitState never completed its completer and dereferenced a null _changeController, so Firebase.initializeApp() hung forever and the app stayed on a blank page. Complete the completer with the error, unsubscribe in either case, and surface it from registerWith as a FirebaseAuthException via guardAuthExceptions. Fixes firebase#18703
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
I approve this, good stuff |
Description
On Flutter web,
Firebase.initializeApp()could hang forever (blank page until a manual reload) when the JS SDK's firstonAuthStateChangedcallback fires with an error — e.g. anIndexedDBLocalPersistence._openDbrejection during initial user restoration.Auth.onWaitInitState()(awaited fromFirebaseAuthWeb.registerWith→ensurePluginInitialized) had two defects on that path:Completer, soawait completer.futurewaited forever._changeController!, which is stillnullduring plugin registration (nothing has subscribed toonAuthStateChangedyet), so the JS callback threw a null-check error and the original error was swallowed.This PR:
isCompleted), soonWaitInitState()rejects instead of hanging;_changeControlleronly when it exists (?.);finally, on both the success and error paths;onWaitInitState()call inregisterWithwith the existingguardAuthExceptions, soFirebase.initializeApp()surfaces a regularFirebaseAuthException(FirebaseError→code/messageconversion) instead of a raw JS object.The happy path is unchanged:
_initUseris still captured from the firstnextcallback andonWaitInitState()still completes normally.Related Issues
Fixes #18703
Tests
New
packages/firebase_auth/firebase_auth_web/test/on_wait_init_state_test.dart(browser test) drivesAuth.onWaitInitState()against a minimal JS stub ofonAuthStateChanged:Run locally with
flutter test --platform chrome(Flutter 3.47.2, chrome-headless-shell 153):mainthe error case fails —TypeError: ... 'TypeErrorImpl' is not a subtype of type 'JSObject'from the_changeController!null check, and without that the future would never complete;on_wait_init_state_test.dart+2: All tests passed!,get_firebase_auth_exception_test.dart+2,auth_emulator_test.dart+11.dart analyzeon the package:No issues found!;dart formatclean.Not run here: the e2e example app / a real browser session with IndexedDB blocked.
Checklist
///).melos run analyze) does not report any problems on my PR.Breaking Change