Angularfire: Feature Request: Support for firestore.settings()

Created on 26 Aug 2020  路  2Comments  路  Source: angular/angularfire

I am using Firebase Emulator to test firestore locally. To do this, I need to pass some settings to the firestore instance, as follows:

````
constructor(private db: AngularFirestore) { }

ngOnInit() {
this.db.firestore.settings({
host: "localhost:8080",
ssl: false
});
}
````

This works, but I have to make sure that this is done before any database operation, else the requests would be sent to the remote firestore database. It would be nice to pass in this config during the initialization of AngularFirestore service, similar to how AngularFirestoreModule.enablePersistence() is implemented.

It could look like this:

````
const firestoreSettings = {
host: "localhost:8080",
ssl: false
}

@NgModule({
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFirestoreModule.settings(firestoreSettings), // <-- like this

//  Or it could look like this
//  AngularFirestoreModule.config({
//    enablePersistence: true,
//    settings: firestoreSettings
//  }),

],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {}
````

Thank you.

Most helpful comment

Add this to the providers array:

// Import for custom settings to connect firestore emulator locally
import { AngularFireFunctionsModule, ORIGIN as FUNCTIONS_ORIGIN } from '@angular/fire/functions';
// Import for custom settings for the AngularFirestore Module
import { AngularFirestoreModule, SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/firestore';

// ... More code
providers: [
    {
      provide: FIRESTORE_SETTINGS,
      useValue: environment.emulator ? {
        host: 'localhost:8080',
        ssl: false,
      } : undefined,
    },
    {
      provide: FUNCTIONS_ORIGIN,
      useValue: environment.emulator ? 'http://localhost:5001' : undefined,
    }
  ]

You can pass custom settings on useValue :)

All 2 comments

Add this to the providers array:

// Import for custom settings to connect firestore emulator locally
import { AngularFireFunctionsModule, ORIGIN as FUNCTIONS_ORIGIN } from '@angular/fire/functions';
// Import for custom settings for the AngularFirestore Module
import { AngularFirestoreModule, SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/firestore';

// ... More code
providers: [
    {
      provide: FIRESTORE_SETTINGS,
      useValue: environment.emulator ? {
        host: 'localhost:8080',
        ssl: false,
      } : undefined,
    },
    {
      provide: FUNCTIONS_ORIGIN,
      useValue: environment.emulator ? 'http://localhost:5001' : undefined,
    }
  ]

You can pass custom settings on useValue :)

@KingDarBoja Awesome, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mypark picture mypark  路  3Comments

jteplitz picture jteplitz  路  3Comments

aucevica picture aucevica  路  3Comments

martinyoussef picture martinyoussef  路  3Comments

KLiFF2606 picture KLiFF2606  路  3Comments