angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Discussion: the road to AngularFire v6

Open jamesdaniels opened this issue 6 years ago • 38 comments

The road to AngularFire v6

Angular 9 is coming soon! Let's kick off discussions on what AngularFire v6 will look like. We've managed to keep the API stable and introduce no (intentional) breaks for over a year! 🎉

Hope everyone has enjoyed this consistency.

Why break at all?

We currently support three Angular (6, 7, and 8) and Firebase majors (5, 6, and 7) with the current version of AngularFire... that's a lot of work.

To support older versions of Firebase we have a number of conditionals and a lot of unneeded code/types.

To maintain support for older versions of Angular, we've been holding back our typescript version and not adopting any new APIs.

Plan of action

Version 5.3:

Release it, WIP here #2187

Version 5.4:

Reimplement @angular/fire/database-deprecated using @angular/fire/database under the hood. It's been raised that database-deprecated has been pretty broken since we've dropped it from our test suite but it is holding back some of our developers from upgrading. We should try to get them on the latest version of 5, before we start breaking things.

Perhaps at this point we'll mark peer support for Angular 9.0 final. So far in my testing the release candidates seem to work fine and we shouldn't need to break a major to support.

Once we've dealt with that:

Version 5.3.1:

Cherry-pick the fixes for the ng add and ng deploy commands.

Version 6:

  • Bump the peer dependency to the latest minor of Firebase (currently v7.6)
  • Bump the peer dependency of Angular to v9
  • Bump the peer dependency of Typescript to bring inline with Angular v9 (currently v3.6)
  • Various bugs / types / export naming (see SEMVER comments in the source)
  • Change our build process to use ng-packagr #2117
  • Drop the angularfire2 shim releases on NPM
  • Add the SDK proxy that AngularFireAnalytics and AngularFireRemoteConfig use in the upcoming 5.3 release (#2187) to all the modules and drop the instance getters.
  • ~Make all modules side-effect free (no longer importing the SDKs)~

Version 6.1:

  • "Lazy" versions of all the "non-lazy" modules. These do not assume the developer has loaded any of the Firebase SDKs and will dynamically import them; obviously some APIs will be different.

Version 7:

  • Drop the "non-lazy" modules
  • Move all our operators, observables, etc. to pure-functions (more on this soon)
  • whatever else we think of by then...

Things we're thinking of:

  • Reduce the amount of code in this library by leaning on RxFire
  • Can we build a migrator for @angular/fire/database-deprecated in a reasonable timespan? If so, I'll drop database-depreciated in version 6, if not we'll punt until version 7. During my investigation I found little evidence that those still using database-depreciated had moved to 5.0 stable; I've decided to drop for 6.0.
  • How different would the "lazy" modules actually be? Can we just migrate over to them in 6 rather than have them be optional until 7?
  • ~Require the user import 'firebase/*' themselves before use of the non-lazy modules, this would allow us to export all the packages under @angular/fire and mark them as having no side-effects.~ ngcc no longer has issue with this
  • Shallow up the exports, if we're entirely side-effect free we can export everything in @angular/fire rather than having sub-packages.
  • Strong type support in the vanilla Firestore SDK is available now with FirestoreDataConverter. Can we leverage this to get some of our Firestore type work for free in AngularFire & make the guarantees "stronger"? Can we use this for production-worthy state-transfer?

jamesdaniels avatar Dec 17 '19 19:12 jamesdaniels

@mgechev - Maybe add Cloud functions/run support for Angular ssr as part of ng deploy?

vikerman avatar Dec 18 '19 17:12 vikerman

@jamesdaniels, I'll be happy to push SSR support with Cloud functions (at first) as part of the next major release.

Cloud functions seems like a good incremental rollout of a more complete & robust dynamic SSR solution. We're a step away from making deployments with pre-rendering generally available. As the next step, we can re-iterate on the dynamic SSR to optimize for cold start.

WDYT?

mgechev avatar Dec 18 '19 19:12 mgechev

looks great! Better documentation on how to use the firebase emulator with angularfire, local database and firestore triggers would be nice too

rubenheymans avatar Jan 06 '20 00:01 rubenheymans

@vikerman @mgechev absolutely. In v6 too I'll change the default setup instructions to be ng add @angular/fire. I'm eager for all the Universal 9 improvements.

@rubenheymans great point. I've been meaning to work on those docs also move our tests over to the emulator by default so they're less flaky (and we're dogfooding the emulator integrations).

jamesdaniels avatar Jan 08 '20 17:01 jamesdaniels

What is the current approach/timeline towards v6? I see there's one big PR here https://github.com/angular/angularfire/pull/2282.

What I'm interested in the most right now is the change to ng-packagr for the build, as it's blocking me (and probably others) from building my application using Bazel in Angular 9. I see it the original issue https://github.com/angular/angularfire/pull/2117 got closed in favor of https://github.com/angular/angularfire/pull/2282, does that mean the work in that branch is close to being done, or it wasn't possible to move to ng-packagr without doing lots of other changes?

Can we contribute in any way right now? Thanks for your great work!

Timebutt avatar Jan 10 '20 19:01 Timebutt

Timeline is the rehaul commit going on master in the next day or two, which will mean canary builds on NPM.

Helping test those builds against ng9 would be very helpful, as I’ll probably have too much on my plate to thoroughly dogfood before the first RC.

jamesdaniels avatar Jan 11 '20 06:01 jamesdaniels

FYI I've cut an initial build of version 6 on NPM 6.0.0-next.0

jamesdaniels avatar Jan 29 '20 00:01 jamesdaniels

Version 6 development is now happening on master. I'm writing the changelog entry now and will be cutting the first RC shortly.

jamesdaniels avatar Jan 30 '20 21:01 jamesdaniels

6.0.0-rc.0 is now up on NPM! And we have release notes.

jamesdaniels avatar Jan 30 '20 23:01 jamesdaniels

more documentation for multiple tenant apps and angularfire would be nice too. So every user has his own database/storage/auth, and a common project where can manage the tenants

rubenheymans avatar Feb 29 '20 16:02 rubenheymans

multiple tenant apps @rubenheymans what do you mean?

hiepxanh avatar Mar 04 '20 10:03 hiepxanh

@hiepxanh https://cloud.google.com/identity-platform/docs/multi-tenancy-quickstart Create separate databases/storage/... for multiple tenants/clients

rubenheymans avatar Mar 04 '20 12:03 rubenheymans

@rubenheymans , i saw in the docs that Firebase doesn't manage multi-tenancy.

johanchouquet avatar Mar 13 '20 11:03 johanchouquet

@rubenheymans the identity platform and firebase authentication do support multi-tenancy. However, Firestore does not offer the ability to create multiple databases in the same project. If you want to have multi-tenancy in an application with Firestore you would need to do it with your data model. The recommendation from the Google Cloud Docs has always been to use separate Projects for each client application "Tenant" - https://firebase.google.com/docs/projects/learn-more#multi-tenancy

puchesjr avatar Mar 15 '20 03:03 puchesjr

AngularFire's DI pattern supports linking to multiple apps, this will be a lot easier in 6.0 now that we're using "providedIn: any" will def write some more docs up on this.

jamesdaniels avatar Mar 15 '20 18:03 jamesdaniels

@jamesdaniels we store client configurations in a global firestore collection when users are attempting to authenticate they provide the organization name - similar to Slack's workspace sign-in. e.g., acmecorp.slack.com. After retrieving the client config for the identity platform it will load the appropriate firebase configuration for authentication.

puchesjr avatar Mar 15 '20 18:03 puchesjr

Not sur if it's too late or not, but I find the remote config documentation a little bit vague on some points:

  • a full example of how to provide settings would be great, the code below is not working even when replacing REMOTE_CONFIG_SETTINGS by SETTINGS imported from the package:
{
  provide: REMOTE_CONFIG_SETTINGS,
  useFactory: () => isDevMode() ? { minimumFetchIntervalMillis: 10_000 } : {}
}
  • how does the above config plays with the filterFresh(x) operator? During dev, using the config with a short interval didn't refresh the config, but adding the operator refreshed it immediately.

Note that this is not a support request 😃 . I will solve my problems, but I must admit that documentation could be more detailed, with some examples.

Thank you.

255kb avatar Mar 19 '20 20:03 255kb

HI everyone!

Just a quick queston here: do we get closer to the v6 for AngularFire ? It'd be so great to be able to upgrade to Angular 9 with all the benefits of Ivy :)!

johanchouquet avatar Mar 23 '20 13:03 johanchouquet

@rubenheymans the identity platform and firebase authentication do support multi-tenancy. However, Firestore does not offer the ability to create multiple databases in the same project. If you want to have multi-tenancy in an application with Firestore you would need to do it with your data model. The recommendation from the Google Cloud Docs has always been to use separate Projects for each client application "Tenant" - https://firebase.google.com/docs/projects/learn-more#multi-tenancy

Thanks I also found this solution and tried to implement this into my all but it's a bit difficult. I don't know how to programmatically manage all the different projects / customers.

rubenheymans avatar Mar 23 '20 15:03 rubenheymans

@rubenheymans I'm happy to provide you with a few scenarios to consider - each has its own pros and cons.

Scenario 1. Single Project using Firebase Auth Multi-tenancy In this scenario, you will need to use database security rules/authorization to ensure data is only read by the appropriate tenant. You can do this by either placing a tenantId on a collection doc for example. Or, you could create tenants as a top-level collection with sub-collection under each tenant. In this example, you can store the tenantId in root collection called something like tenantConfigs, when a user comes to authentication you can do something similar to slack and present them with an input field to enter their tenant name and retrieve the tenantId from your tenantConfigs you now use this with firebase.auth().tenantId = tenantId from firestore to authenticate the user.

Scenario 2. Single project per tenant without hosting In this scenario, you will use Google Cloud Platform api to create a new project and enable the services you need to use, you will also need to use the firebase api to set project details and then you will capture all of the connection details for connecting to the client and persist in a global firestore identified by a tenantId for example, typically your only organization has access to this global firestore and your client-side interacts with it through an api using Cloud Funcs or CloudRun as example. This global store is beneficial as it can be used by you internally to track things like organization details, payment status, organization aggregate data (e.g., total users) etc. The Firebase SDK provides the ability to use multiple firebase projects which you can inject into your application

Scenario 3. Single project per tenant including hosting In this scenario, you will do everything similar to Scenario 2 - you will use the Google Cloud Platform api to create a new project and enable the service you need to use, you will need to also use the firebase api to set project details and then you will deploy your code - you could use something like Google deployment manager to automate a good amount of this. Once the project is launched you now have the task of keeping multiple projects update anytime you deploy new code / bug fixes, etc. I would reserve this method for large Enterprise or Government as an example.

Here is a Workflow you can use for Scenarios 2 and 3

I hope the information helps.

puchesjr avatar Mar 23 '20 16:03 puchesjr