Friday 19 March 2021

How to connect emulator to redux-saga-firebase app

I'm trying to set up the emulator for firebase. My app is built with https://redux-saga-firebase.js.org/ The documentation says to add code like this to point the app to the emulator. Or maybe it's these directions?

  const db = firebaseApp.firestore();

  // ADD THESE LINES
  if (window.location.hostname === "localhost") {
    console.log("localhost detected!");
    db.settings({
      host: "localhost:8080",
      ssl: false
    });
  }

Here is my file, where firebase is set up. Notice, firebaseApp is initialized differently.

import * as firebase from 'firebase/app';
import '@firebase/firestore';
import ReduxSagaFirebase from 'redux-saga-firebase';
import { FIREBASE_CONFIG } from '../keys';

const config = FIREBASE_CONFIG;

export const firebaseApp = firebase.initializeApp(config);

export const rsf = new ReduxSagaFirebase(firebaseApp);

I add this, but it still points to production data.

if (window.location.hostname === "localhost") {
    rsf.settings({
        host: "localhost:8080",
        ssl: false
    });
}

I have also tried this.

let config = FIREBASE_CONFIG;

if (window.location.hostname === "localhost") {
    config = {
      ...config,
      databaseURL: 'https://localhost:8080?ns=<<myProjectId>>',
    }
}

And this.

   if (location.hostname === "localhost") {
     firebaseApp.useEmulator("localhost", 8080);
   }

The emulators are running, but how do I connect my app?



from How to connect emulator to redux-saga-firebase app

No comments:

Post a Comment