Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I connect to the local emulators? #283

Open
sharaf84 opened this issue Mar 2, 2024 · 1 comment
Open

How can I connect to the local emulators? #283

sharaf84 opened this issue Mar 2, 2024 · 1 comment

Comments

@sharaf84
Copy link

sharaf84 commented Mar 2, 2024

I'd like to connect to the local emulators for Firestore and Auth,
here is a code sample that works using native Firebase packages:

import { initializeApp } from "firebase/app";
import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
import { connectAuthEmulator, getAuth } from "firebase/auth";
import { firebaseConfig } from "./env";

export const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);
connectFirestoreEmulator(db, "127.0.0.1", 8080);
export const auth = getAuth(app);
connectAuthEmulator(auth, "http://127.0.0.1:9099");

How can I implement this code using "react-admin-firebase"?

@sharaf84 sharaf84 changed the title How can I connect to local emulators? How can I connect to the local emulators? Mar 2, 2024
@luckyape
Copy link

im not saying its the right way but its how i got things to work:

import firebase from "firebase/compat/app";
import "firebase/compat/firestore";
import "firebase/compat/storage";
import "firebase/compat/auth";
import { getFunctions, connectFunctionsEmulator } from "firebase/functions";
import { getFirestore, connectFirestoreEmulator } from "firebase/firestore";
import {
FirebaseAuthProvider,
FirebaseDataProvider,
} from "react-admin-firebase/dist/src";

let firebaseApp;

if (!firebase.apps.length) {
firebaseApp = firebase.initializeApp(firebaseConfig);
} else {
firebaseApp = firebase.app(); // if already initialized, use that one
}
export const storage = getStorage(firebaseApp);
export const functions = getFunctions(firebaseApp);

const auth = firebase.auth(firebaseApp);
const db = getFirestore();
const isDevelopment =
process.env.NODE_ENV === "development" ||
process.env.FUNCTIONS_EMULATOR === "true";

if (isDevelopment) {
connectFunctionsEmulator(functions, "127.0.0.1", 5001);
auth.useEmulator("http://127.0.0.1:9099");
connectFirestoreEmulator(db, "localhost", 8080);
connectStorageEmulator(storage, "localhost", 9199);
}

const dataProvider = FirebaseDataProvider(firebaseConfig, {
app: firebaseApp,
});

const authProvider = FirebaseAuthProvider(firebaseConfig, {
app: firebaseApp,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants