feat: add setFirebaseOptions() for runtime multi-tenant Firebase configuration#192
Open
Aravinthan-J wants to merge 3 commits into
Open
feat: add setFirebaseOptions() for runtime multi-tenant Firebase configuration#192Aravinthan-J wants to merge 3 commits into
Aravinthan-J wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
setFirebaseOptions()method that allows apps to initialize Firebase with credentials provided at runtime, rather than relying solely on staticgoogle-services.json/GoogleService-Info.plistfiles baked into the binary.This unblocks multi-tenant SaaS apps where each tenant operates their own Firebase project and the correct credentials are only known after the user authenticates.
Closes #60
Motivation
In multi-tenant apps, push notification tokens must be scoped to the correct Firebase project per tenant. There is currently no way to do this with this plugin — the only path was to either:
This PR upstreams the implementation from an internal fork that has been running in production on Capacitor 5/6/7.
Changes
src/definitions.tsFirebaseOptionsinterfacesetFirebaseOptions(options: FirebaseOptions): Promise<void>toFCMPluginsrc/web.tssetFirebaseOptions()stub (throwsunimplemented— native-only)Android (
FCMPlugin.java)Creates a named secondary
FirebaseApp("FCM") so it does not conflict with or re-initialize any default app already present fromgoogle-services.json. AllgetToken()/refreshToken()/setAutoInit()/isAutoInitEnabled()calls are automatically routed through the secondary app when set.iOS (
FCMPlugin.swift)load()now checks for the presence ofGoogleService-Info.plistbefore callingFirebaseApp.configure(), so apps without a plist don't crash on startupsetFirebaseOptions()configures the default Firebase app with runtime credentials; fails fast with a clear error if Firebase is already initialized (Firebase SDK limitation — re-initialization is not supported on iOS)Usage
Platform behaviour summary
FirebaseApp("FCM")GoogleService-Info.plistKnown limitations / follow-up
FirebaseApp.configure()is called it cannot be undone. Apps that need to switch tenants at runtime on iOS must restart.Messaging(app:)API, sogetToken()on iOS always uses the default app (which is configured bysetFirebaseOptions()).Testing
Tested on:
Existing behaviour is fully preserved when
setFirebaseOptions()is never called.