From e61ed5210f71e973adc088a659570a0bce133a2a Mon Sep 17 00:00:00 2001 From: Daniel Reinoso Date: Tue, 24 Sep 2024 09:04:10 -0300 Subject: [PATCH] Fix firebase emulator --- src/index.scss | 5 +++++ src/shared/utils/firebase.tsx | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/index.scss b/src/index.scss index dcaa2ad22a..49b9749dad 100644 --- a/src/index.scss +++ b/src/index.scss @@ -255,3 +255,8 @@ a:visited { background-color: transparent; text-decoration: none; } + +.firebase-emulator-warning { + font-size: 10px; + height: 10px; +} diff --git a/src/shared/utils/firebase.tsx b/src/shared/utils/firebase.tsx index 6755110688..1be275d461 100644 --- a/src/shared/utils/firebase.tsx +++ b/src/shared/utils/firebase.tsx @@ -18,6 +18,7 @@ interface FirebaseError extends Error { const app = firebase.initializeApp(config.firebase); let db = firebase.firestore(); +// WARNING: This function is enabling local emulator. If removed, move the emulator config out of this function enableUnlimitedCachePersistence(); // Function to handle Firestore persistence errors function handlePersistenceError(err: any) { @@ -79,21 +80,19 @@ function enableUnlimitedCachePersistence() { cacheSizeBytes: CACHE_SIZE_LIMIT, }; db.settings(settings); - + // Enable Firestore emulator in the local environment + if (REACT_APP_ENV === Environment.Local) { + firebase.auth().useEmulator(local.firebase.authDomain); + firebase + .firestore() + .useEmulator( + "localhost", + Number(local.firebase.databaseURL.split(/:/g)[2]), + ); + } db.enablePersistence({ synchronizeTabs: true }).catch(handlePersistenceError); } -// Enable persistence in the local environment (with Firestore and Auth emulators) -if (REACT_APP_ENV === Environment.Local) { - firebase.auth().useEmulator(local.firebase.authDomain); - firebase - .firestore() - .useEmulator( - "localhost", - Number(local.firebase.databaseURL.split(/:/g)[2]), - ); -} - let perf; if (typeof window !== "undefined" && typeof window.fetch !== "undefined") { perf = getPerformance(app);