Skip to content

Commit

Permalink
connect emulators based on env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
notsidney committed May 2, 2022
1 parent 97076b6 commit 580c67c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/firebase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@ import appConfig from "./config";

firebase.initializeApp(appConfig);

// Connect emulators based on env vars
const envConnectEmulators =
process.env.NODE_ENV === "test" ||
process.env.REACT_APP_FIREBASE_EMULATOR === "true";

export const auth = firebase.auth();
if (envConnectEmulators && !(window as any).firebaseAuthEmulatorStarted) {
auth.useEmulator("http://localhost:9099");
(window as any).firebaseAuthEmulatorStarted = true;
}

export const db = firebase.firestore();
db.settings({
cacheSizeBytes: firebase.firestore.CACHE_SIZE_UNLIMITED,
ignoreUndefinedProperties: true,
});
db.enablePersistence({ synchronizeTabs: true });
if (!(window as any).firebaseDbStarted) {
if (envConnectEmulators) db.useEmulator("localhost", 9299);
else db.enablePersistence({ synchronizeTabs: true });
(window as any).firebaseDbStarted = true;
}

export const bucket = firebase.storage();
export const functions = firebase.functions();
Expand Down

0 comments on commit 580c67c

Please sign in to comment.