Home > Back-end >  What's the difference between Firebase AngularFireAuth and Auth?
What's the difference between Firebase AngularFireAuth and Auth?

Time:09-29

There are two way of importing Authentication.

The first one is

import { AngularFireAuth } from '@angular/fire/compat/auth';

the second one is

import { Auth } from '@angular/fire/auth';

What is the difference?

CodePudding user response:

Firebase introduced a major overhaul of its JavaScript APIs in mid-2021 to allow unused code from the SDKs to be removed during your build process (a process known as tree-shaking). In these new SDKs they also introduced a compat path, that uses the new SDK but the old syntax (and also can't remove the unused code).

The compat path in AngularFire uses the compatibility layer of the v9 JavaScript SDKs.

From the AngularFire docs:

AngularFire has a new tree-shakable API, however this is still under active development and documentation is in the works, so we suggest most developers stick with the [Compatibility] API for the time being. See the v7 upgrade guide for more information.

So for the moment the recommendation is to use the compat mode of AngularFire, which means it does run with the v9 releases of the JavaSCript SDK, but doesn't gain the benefits of tree-shaing in the AngularFire modules that you use. Functionality-wise the two should be the same though.

  • Related