-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Feature request: add support for multiple firebase projects #1240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is already supported. Just initialize more than one Firebase app in your ngModule and then switch/swap/rename them via Here's a quick stackblitz demonstrating https://stackblitz.com/edit/angular-aw3pyc?file=app%2Fapp.component.ts I'll add to the docs, in the meantime the DI docs for Angular are a good start. https://angular.io/guide/dependency-injection-in-action |
@jamesdaniels Thank you for the support! So I've missed a bit how Angular injection works. Could you still show how to inject multiple instances of the same service to same component? The What do I do when I need all three in the same service? |
Hi @jamesdaniels, I'm not clear with your stackblitz. In But, in Console, the I've tried to rename 2 apps in And, when I switched the position of 2 Please help, thanks. |
Also struggling to find how to implement 2 Firebase instances in the same project.
|
hi, |
@nguyenluucuong, @magleahy, @lemas-projetpos I've opened new issue #1305 to track the documentation of this, hopefully we'll then find out how to do it properly. |
You could take a look at the solution I am using here. |
@jamesdaniels example works for swapping the It also seems like the FirebaseApp object does not expose the same methods that, for example, the |
FYI |
@jamesdaniels I also need to delete the firebase coordinates as the user signs out. Thanks in advance. Kind regards, |
Just to share as I was looking into multiple issues to find out something around Firestore, you may look into this stalkblitz, or the stackoverflow item in case. |
Hi,
thank you for the awesome library, especially the 5.0, it's forming to be the holy grail of angular apps with Firestore.
I need to use multiple projects with Angularfire, and currently it's not as developer friendly as it could be.
I request to have either
#1026 touches this issue a bit, but as far as I can see there is no final resolution.
As far as I can see the core Firebase library has support for this, and the Angularfire2 bootstrapping mechanism even takes the app id as parameter, but that is not really used anywhere and the different providers inject just the default app instance.
Option 1. could be implemented as one central service that would keep track of different FirebaseApps and have a map of those as well as different services (Database, Auth, Firestore etc.) that would be keyed by the app name.
AngularFireModule.initializeApp should be changed to take in multiple pairs of FirebaseAppConfig and appName. The first one would be the one that is used when using the normal, current injection. This way the backwards compatibility would be top notch.
The initialization logic would loop through the different configs, and set those to the central service and it's maps + return the same module definitions as the current implementation returns.
This would enable us to use this in components or services:
This is also forward compatible if Angular ever supports more sophisticated injection methods.(somekind of markers or other ways to allow injection of different instances of the same class)
Option 2. would be simply documenting something along these lines:
app.module.ts:
angularfire.extensions.ts:
The above code has been briefly tested and found working.
Obviously regardless which option is chosen, it is required that the underlying code does not make assumptions that there is only one instance of any given class out in the wild. As far as I've red the code we're safe here.
The text was updated successfully, but these errors were encountered: