Title: Feature request: add support for multiple firebase projects · Issue #1240 · angular/angularfire · GitHub
Open Graph Title: Feature request: add support for multiple firebase projects · Issue #1240 · angular/angularfire
X Title: Feature request: add support for multiple firebase projects · Issue #1240 · angular/angularfire
Description: 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...
Open Graph Description: 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...
X Description: 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...
Opengraph URL: https://github.com/angular/angularfire/issues/1240
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature request: add support for multiple firebase projects","articleBody":"Hi,\r\n\r\nthank you for the awesome library, especially the 5.0, it's forming to be the holy grail of angular apps with Firestore.\r\n\r\nI need to use multiple projects with Angularfire, and currently it's not as developer friendly as it could be. \r\n\r\nI request to have either\r\n\r\n1. Builtin support for bootstrapping and injecting multiple instances of the app, database, firestore, auth etc. or...\r\n2. Documentation level blueprint how to do it yourself\r\n\r\n#1026 touches this issue a bit, but as far as I can see there is no final resolution.\r\n\r\nAs 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.\r\n\r\nOption 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. \r\n\r\nAngularFireModule.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.\r\n\r\nThe 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.\r\n\r\n```typescript\r\nimports: [\r\n AngularFireModule.initializeApp(environment.myFirebaseConfig1, 'firebase1', environment.myFirebaseConfig2, 'firebase2')\r\n]\r\n```\r\n\r\nThis would enable us to use this in components or services:\r\n\r\n```typescript\r\n...\r\nexport class LoginComponent implements OnInit, AfterContentChecked {\r\n\r\n private auth1: AngularFireAuth\r\n private auth2: AngularFireAuth\r\n\r\n constructor(\r\n private auth: AngularFireAuth, //This would be the default, configured using myFirebaseConfig1 above\r\n private angularFireService: AngularFireService //New service, containing all confs and related services\r\n) {\r\n this.auth1 = auth\r\n this.auth2 = angularFireService.getAuth('firebase2') //the same id as given in initializeApp call above\r\n }\r\n...\r\n```\r\n\r\nThis 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)\r\n\r\nOption 2. would be simply documenting something along these lines: \r\n\r\napp.module.ts:\r\n```typescript\r\nimport { MyAngularFireAuth, MyAngularFireDatabase, MyAngularFirestore, MyFirebaseApp, _firebaseAppFactory } from './angularfire.extensions'\r\n\r\n@NgModule({\r\n...\r\nproviders: [\r\n { provide: MyFirebaseApp, useValue: _firebaseAppFactory(environment.myOtherFirebaseConfig, 'myFirebase') },\r\n { provide: MyAngularFirestore, deps: [MyFirebaseApp], useFactory: \r\n (myFirebaseApp: MyFirebaseApp): MyAngularFirestore => { \r\n return new MyAngularFirestore(myFirebaseApp, true) \r\n }\r\n },\r\n { provide: MyAngularFireAuth, deps: [MyFirebaseApp], useFactory: \r\n (myFirebaseApp: MyFirebaseApp): MyAngularFireAuth => { \r\n return new MyAngularFireAuth(myFirebaseApp) \r\n }\r\n },\r\n { provide: MyAngularFireDatabase, deps: [MyFirebaseApp], useFactory: \r\n (myFirebaseApp: MyFirebaseApp): MyAngularFireDatabase => { \r\n return new MyAngularFireDatabase(myFirebaseApp) \r\n }\r\n }\r\n ]\r\n...\r\n})\r\nexport class AppModule { }\r\n```\r\n\r\nangularfire.extensions.ts:\r\n```typescript\r\nimport { FirebaseApp, FirebaseAppConfig } from 'angularfire2'\r\nimport { AngularFireAuth } from 'angularfire2/auth'\r\nimport { AngularFireDatabase } from 'angularfire2/database'\r\nimport { AngularFirestore } from 'angularfire2/firestore'\r\n\r\nimport * as firebase from 'firebase'\r\n\r\nexport function _firebaseAppFactory(config: FirebaseAppConfig, appName?: string): FirebaseApp {\r\n try {\r\n if (appName) {\r\n return firebase.initializeApp(config, appName) as FirebaseApp;\r\n } else {\r\n return firebase.initializeApp(config) as FirebaseApp;\r\n }\r\n }\r\n catch (e) {\r\n if (e.code === \"app/duplicate-app\") {\r\n return firebase.app(e.name) as FirebaseApp;\r\n }\r\n\r\n return firebase.app(null!) as FirebaseApp;\r\n }\r\n}\r\n\r\nexport class MyAngularFireAuth extends AngularFireAuth {\r\n \r\n}\r\n\r\nexport class MyFirebaseApp extends FirebaseApp {\r\n \r\n}\r\n\r\nexport class MyAngularFireDatabase extends AngularFireDatabase {\r\n \r\n}\r\n\r\nexport class MyAngularFirestore extends AngularFirestore {\r\n\r\n}\r\n```\r\n\r\nThe above code has been briefly tested and found working.\r\n\r\nObviously 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.","author":{"url":"https://github.com/swftvsn","@type":"Person","name":"swftvsn"},"datePublished":"2017-10-10T08:05:40Z","url":"https://github.com/angular/angularfire/issues/1240"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5fc0e352-a436-6e62-d57d-00d1bf388640 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3CA:1EDA:EA652C:138683D:6B0366D6 |
| html-safe-nonce | 07938ee194e310f6c852683e86821ecd4376c17c313f49c228014fa18e9087a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0NBOjFFREE6RUE2NTJDOjEzODY4M0Q6NkIwMzY2RDYiLCJ2aXNpdG9yX2lkIjoiNDUyODg4ODQzOTU1NDQwMjAwNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ad41b30785e254e5f0392fcec27a79313c1aee8f98bef2f927bedfe2a0cfbf60 |
| hovercard-subject-tag | issue:264133966 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angularfire/1240/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fbe5c52563fb4f8f7ae16a6569b443c10675f738fe6233ea7c0d63197036c028/angular/angularfire/issues/1240 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fbe5c52563fb4f8f7ae16a6569b443c10675f738fe6233ea7c0d63197036c028/angular/angularfire/issues/1240 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | swftvsn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angularfire git https://github.com/angular/angularfire.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 49453413 |
| octolytics-dimension-repository_nwo | angular/angularfire |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49453413 |
| octolytics-dimension-repository_network_root_nwo | angular/angularfire |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width