Sekrab Garage

Angular Firebase Authentication

Update to Angular 19

AngularTip January 21, 25
Subscribe to Sekrab Parts newsletter.
Series:

AngularFire

Previously we covered Authentication in Angular and why it was hard to wrap our heads around. To pick up from there, in this series of articles we are going to adopt Firebase Auth as a third party, and investigate different options: managing users remotely, and using Firebase for Authentication only.
  1. one year ago
    I - Setting up AngularFire with Authentication
  2. one year ago
    II - Firebase User Management in Angular
  3. one year ago
    III - Firebase For Authentication only in Angular
  4. few hours ago
    Update to Angular 19

Last time we had Firebase Auth integrated at Angular 17. Here is a quick update to keep it fresh in Angular 19.

anchorProviders

Before update, our main.ts looked like this

// main.ts before update

const fbApp = () => initializeApp(firebaeConfigHere);
const authApp = () => initializeAuth(fbApp(), {
  persistence: browserSessionPersistence,
  popupRedirectResolver: browserPopupRedirectResolver
});

const firebaseProviders: EnvironmentProviders = importProvidersFrom([
  provideFirebaseApp(fbApp),
  provideAuth(authApp),
]);

bootstrapApplication(AppComponent, {
  providers: [
	  // ...
    firebaseProviders
  ],
});

The updates touch the importProvidersFrom, it is no longer needed

// main.ts thew new
  
const firebaseProviders = [
  provideFirebaseApp(fbApp),
  provideAuth(authApp),
];

bootstrapApplication(AppComponent, {
  providers: [
	// expand it
    ...firebaseProviders
  ],
});

anchorApp initializer token

One way to inject the AuthState on application start was to use the APP_INITIALIZER token with no return, and one injection, like this

{
    provide: APP_INITIALIZER,
    // dummy factory
    useFactory: () => () => {},
    multi: true,
    // injected depdencies, this will be constructed immidiately
    deps: [AuthState],
  },

This simply becomes this:

// new provider
provideAppInitializer(() => {
  inject(AuthState);
  return null;
}),

That's it. Looks like the new Firebase library still works as designed.

  1. one year ago
    I - Setting up AngularFire with Authentication
  2. one year ago
    II - Firebase User Management in Angular
  3. one year ago
    III - Firebase For Authentication only in Angular
  4. few hours ago
    Update to Angular 19