I have a mono repo project with my frontend and backend together.
I am trying to set up the Firebase emulator on both places where I do initializeApp
I suspect that setting up the emulator in both places makes them collide.
This is the frontend configuration
// Initialize Firebase
const firebaseConfig = {
...window.config
};
const app = firebase.initializeApp(firebaseConfig);
// Ensure no Firebase Auth calls are made before configuring the emulator
if (window.env === "emulator") {
// Set the auth emulator BEFORE any auth calls are made
firebase.auth().useEmulator("http://127.0.0.1:9099", { disableWarnings: true });
// Set the Firestore emulator
firebase.firestore().useEmulator("localhost", 8080);
}
// Now that the emulator is set, you can safely use the Firebase Auth instance
const auth = firebase.auth();
// Set up other authentication methods
const signInAnonymously = firebase;
If I don’t run my backend everything works fine, and the part of my app that uses the frontend firebase does work perfectly.
This is the set up for the backend:
const adminDB = require("firebase-admin");
// Initialize the Firebase Admin SDK
adminDB.initializeApp({
credential: adminDB.credential.cert(serviceAccount),
databaseURL: config.firebaseConfig.databaseURL,
databaseAuthVariableOverride: {
uid: "service" // indicates that this is a service account and not an actual user
}
});
const firestore = adminDB.firestore();
// Check if using Firestore emulator
if (process.env.FIRESTORE_EMULATOR_HOST) {
firestore.settings({
host: process.env.FIRESTORE_EMULATOR_HOST,
ssl: false, // Emulator does not use SSL
experimentalForceLongPolling: true, // Force HTTP/1 instead of gRPC
useFetchStreams: false
});
}
Same way, if I try one of my endpoints using postman I get fetch data from my firebase emulator.
but at the time I open my dashboard view, were multiple request both from front and back are being made, I get the following error:
“Firebase: Auth instance has already been used to make a network call. Auth can no longer be configured to use the emulator. Try calling “connectAuthEmulator()” sooner. (auth/emulator-config-failed).”
Any ideas on how to aboard this?
Thanks in advance
Be able to have the firebase emulator running with auth and firestore locally on my app
2