fix(auth, iOS): guard URL handlers when no FirebaseApp is configured - #18641
fix(auth, iOS): guard URL handlers when no FirebaseApp is configured#18641jobweegink wants to merge 1 commit into
Conversation
`application(_:open:options:)` and `scene(_:openURLContexts:)` call `Auth.auth()` unconditionally. When the default FirebaseApp has not been configured yet (an app that calls `Firebase.initializeApp` from Dart with explicit options after start-up, or a debug build that never initialises Firebase), `Auth.auth()` hits FirebaseAuth's fatal "The default FirebaseApp instance must be configured before the default Auth instance can be initialized" and the process dies on any URL delivered through the app's URL schemes. `ensureAPNSTokenSetting()` in the same file already guards with `FirebaseApp.app() != nil`; this applies the same guard to the two URL handlers, returning `false` (not handled) when no app is configured.
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. |
russellwheatley
left a comment
There was a problem hiding this comment.
Thanks for tracking this down, the repro steps are clear and the guard matches the pattern ensureAPNSTokenSetting() already uses in this file.
Left two suggestions: logging a debug-only breadcrumb when a URL gets silently dropped, so it's easier to notice in dev builds if this path fires and a real deep link ends up going nowhere.
Also, the CLA check is currently failing, could you sign it at https://cla.developers.google.com/ so this can get merged? 🙏
| // Auth.auth() traps when no FirebaseApp has been configured yet (e.g. an | ||
| // app that initialises Firebase from Dart-side options after start-up). | ||
| guard FirebaseApp.app() != nil else { return false } | ||
| return Auth.auth().canHandle(url) |
There was a problem hiding this comment.
Might be worth a debug-only log here so it's visible during development that a URL got dropped because Firebase wasn't configured yet.
| // Auth.auth() traps when no FirebaseApp has been configured yet (e.g. an | |
| // app that initialises Firebase from Dart-side options after start-up). | |
| guard FirebaseApp.app() != nil else { return false } | |
| return Auth.auth().canHandle(url) | |
| // Auth.auth() traps when no FirebaseApp has been configured yet (e.g. an | |
| // app that initialises Firebase from Dart-side options after start-up). | |
| guard FirebaseApp.app() != nil else { | |
| #if DEBUG | |
| print( | |
| "[firebase_auth] Ignoring URL because no FirebaseApp is configured yet. " + | |
| "Call Firebase.initializeApp() before this URL is delivered if Auth should handle it." | |
| ) | |
| #endif | |
| return false | |
| } | |
| return Auth.auth().canHandle(url) |
|
|
||
| public func scene(_ scene: UIScene, openURLContexts urlContexts: Set<UIOpenURLContext>) -> Bool | ||
| { | ||
| guard FirebaseApp.app() != nil else { return false } |
There was a problem hiding this comment.
Same here for consistency with the other handler.
| guard FirebaseApp.app() != nil else { return false } | |
| guard FirebaseApp.app() != nil else { | |
| #if DEBUG | |
| print( | |
| "[firebase_auth] Ignoring URL because no FirebaseApp is configured yet. " + | |
| "Call Firebase.initializeApp() before this URL is delivered if Auth should handle it." | |
| ) | |
| #endif | |
| return false | |
| } |
Description
FLTFirebaseAuthPlugin(iOS) handles incoming URLs inapplication(_:open:options:)andscene(_:openURLContexts:)by callingAuth.auth()unconditionally. When the defaultFirebaseApphas not been configured yet,Auth.auth()hits FirebaseAuth's fatal errorand the process dies on any URL delivered through one of the app's
CFBundleURLSchemes.This happens in apps that initialise Firebase from Dart with explicit
FirebaseOptions(noGoogleService-Info.plist) some time after start-up — e.g. after reading which environment to use from local storage — and in debug/test binaries that never callFirebase.initializeAppat all. In both cases the plugin is still registered as an app/scene lifecycle delegate and receives the URL.ensureAPNSTokenSetting()in the same file already guards withFirebaseApp.app() != nil. This PR applies the same guard to the two URL handlers: when no app is configured they returnfalse(not handled) instead of trapping.Reproduction (firebase_auth 6.6.1, iOS 26 simulator): a
CFBundleURLTypesentry with a custom scheme, noGoogleService-Info.plist,Firebase.initializeAppnot yet called, thenxcrun simctl openurl booted "<scheme>:///x"→ crash inscene(_:openURLContexts:)(Auth.swift:151,FLTFirebaseAuthPlugin.swift:194).Related Issues
None found for this exact trap; happy to link one if maintainers know of it.
Checklist
FirebaseApp.configure. I can add one if you point me at the right place.///).melos run analyze) does not report any problems on my PR.Breaking Change