import { InjectionToken , Inject , isDevMode , ModuleWithProviders , NgModule , NgZone , Optional , PLATFORM_ID , VERSION as NG_VERSION , Version } from '@angular/core' ; import firebase from 'firebase/compat/app' ; import { FirebaseOptions , FirebaseAppSettings } from 'firebase/app' ; import { VERSION } from '@angular/fire' ; import { FirebaseApp } from './firebase.app' ; export const FIREBASE_OPTIONS = new InjectionToken < FirebaseOptions > ( 'angularfire2.app.options' ) ; export const FIREBASE_APP_NAME = new InjectionToken < string | undefined > ( 'angularfire2.app.name' ) ; export function ɵfirebaseAppFactory ( options , zone , nameOrConfig ? ) { const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]' ; const config = typeof nameOrConfig === 'object' && nameOrConfig || { } ; config . name = config . name || name ; const existingApp = firebase . apps . filter ( app => app && app . name === config . name ) [ 0 ] ; const app = ( existingApp || zone . runOutsideAngular ( ( ) => firebase . initializeApp ( options , config as any ) ) ) ; try { if ( JSON . stringify ( options ) !== JSON . stringify ( app . options ) ) { const hmr = ! ! ( module as any ) . hot ; log ( 'error' , `${ app . name } Firebase App already initialized with different options${ hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.' }` ) ; } } catch ( e ) { } return new FirebaseApp ( app ) ; } const log = ( level , ... args ) => { if ( isDevMode ( ) && typeof console !== 'undefined' ) { console [ level ] ( ... args ) ; } } ; const FIREBASE_APP_PROVIDER = { provide : FirebaseApp , useFactory : ɵfirebaseAppFactory , deps : [ FIREBASE_OPTIONS , NgZone , [ new Optional ( ) , FIREBASE_APP_NAME ] ] } ; @ NgModule ( { providers : [ FIREBASE_APP_PROVIDER ] } ) export class AngularFireModule { static initializeApp ( options , nameOrConfig ? ) { return { ngModule : AngularFireModule , providers : [ { provide : FIREBASE_OPTIONS , useValue : options } , { provide : FIREBASE_APP_NAME , useValue : nameOrConfig } ] } ; } constructor ( @ Inject ( PLATFORM_ID ) platformId ) { firebase . registerVersion ( 'angularfire' , VERSION . full , 'core' ) ; firebase . registerVersion ( 'angularfire' , VERSION . full , 'app-compat' ) ; firebase . registerVersion ( 'angular' , NG_VERSION . full , platformId . toString ( ) ) ; } }