Document properly how to use multiple Firebase projects in one app
See original GitHub issueThere’s a lenghty discussion about this in #1240, and one stackblitz example how to do it, thanks for that!
The comments keep piling, so it seems this is still a source of frustration to people.
The documentation should include examples how to…
- Configure 2 or more projects (for an example projects a, b and c)
- inject realtime database or firestore pointing to project b to Angular component
- inject realtime database or firestore pointing to project c to Angular service (annotated with
@Injectable()
) - inject two instances of realtime database or firestore pointing to project b and c configuration to Angular component
- inject two instances of realtime database or firestore pointing to project b and c configuration to Angular service (annotated with
@Injectable()
)
So, essentially how to inject like this:
import { Injectable } from '@angular/core'
import { AngularFireDatabase } from 'angularfire2/database'
@Injectable()
export class MyService {
constructor(
private storeAppDb: AngularFireDatabase,
private invoicingAppDb: AngularFireDatabase
) {
}
}
I don’t think Angular supports injection scheme like that, but a blueprint how to achieve the same would be nice. (If I can choose which one to inject, then I can make two wrapper services, that I can inject…)
It would be nice though to be just able to say:
import { Injectable } from '@angular/core'
@Injectable()
export class MyService {
constructor(
private angularfire: AngularFire
) {
const firestore1 = angularfire.firestore('conf1')
const firestore2 = angularfire.firestore('conf2')
}
}
which would return the angularfireified firestore etc. services.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Configure multiple projects | Firebase - Google
This page describes how to use more than one Firebase project in your app. Many apps need only a single Firebase project and...
Read more >Using multiple Firebase projects in your Android App
Firebase Android SDK is designed to work with one Firebase project by default. But it is quite possible to access multiple projects in...
Read more >Multiple Firebase projects in one app - Stack Overflow
Firebase now supports accessing multiple projects in one app. No need to go the micro-community route. Here is the tutorial on how to...
Read more >Use multiple Firebase projects properly in WEB application ...
1.Use multiple Firebase Projects at the same program ... If you want to copy data between different Firebases, do the following: # copy...
Read more >Deploy Hosting Site to Multiple Firebase Projects - codeburst
By completing the above task successfully you will have two files called .firebaserc , firebase.json These two files handle all of the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
merci 😃
@swftvsn My solution is implemented in an Ionic application that I am working on… This is tested and working (so far 😃 )
Below is my configuration:
Say the 2 Firebase application configuration variables are firebaseConfigA & firebaseConfigB with their names ‘appA’ & 'appB ’ stored in firebaseAppNameA & firebaseAppNameB.
Note: It is recommended that all such configuration variables are stored in a separate configuration file / custom webpack environment files. The variables will be imported wherever required from here. In my case, I have custom webpack environment setup. If you need help with setting up environments using custom webpack for Ionic, check out this fantastic post from @gshigeto: https://github.com/gshigeto/ionic-environment-variables
Initializing the Firebase applications in your application’s ngModule is not required as this will now be done through a service as shown below.
To the code…
All my Firebase related function are handled in a separate service:
Import the above service in your application’s ngModule.
Now, using the service in a component where I connect to both applications:
Hope this helps.