Skip to content

Commit e61ed52

Browse files
committed
Fix firebase emulator
1 parent c85af4d commit e61ed52

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/index.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,8 @@ a:visited {
255255
background-color: transparent;
256256
text-decoration: none;
257257
}
258+
259+
.firebase-emulator-warning {
260+
font-size: 10px;
261+
height: 10px;
262+
}

src/shared/utils/firebase.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface FirebaseError extends Error {
1818
const app = firebase.initializeApp(config.firebase);
1919
let db = firebase.firestore();
2020

21+
// WARNING: This function is enabling local emulator. If removed, move the emulator config out of this function
2122
enableUnlimitedCachePersistence();
2223
// Function to handle Firestore persistence errors
2324
function handlePersistenceError(err: any) {
@@ -79,21 +80,19 @@ function enableUnlimitedCachePersistence() {
7980
cacheSizeBytes: CACHE_SIZE_LIMIT,
8081
};
8182
db.settings(settings);
82-
83+
// Enable Firestore emulator in the local environment
84+
if (REACT_APP_ENV === Environment.Local) {
85+
firebase.auth().useEmulator(local.firebase.authDomain);
86+
firebase
87+
.firestore()
88+
.useEmulator(
89+
"localhost",
90+
Number(local.firebase.databaseURL.split(/:/g)[2]),
91+
);
92+
}
8393
db.enablePersistence({ synchronizeTabs: true }).catch(handlePersistenceError);
8494
}
8595

86-
// Enable persistence in the local environment (with Firestore and Auth emulators)
87-
if (REACT_APP_ENV === Environment.Local) {
88-
firebase.auth().useEmulator(local.firebase.authDomain);
89-
firebase
90-
.firestore()
91-
.useEmulator(
92-
"localhost",
93-
Number(local.firebase.databaseURL.split(/:/g)[2]),
94-
);
95-
}
96-
9796
let perf;
9897
if (typeof window !== "undefined" && typeof window.fetch !== "undefined") {
9998
perf = getPerformance(app);

0 commit comments

Comments
 (0)