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

Fix firebase emulator #2737

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,8 @@ a:visited {
background-color: transparent;
text-decoration: none;
}

.firebase-emulator-warning {
font-size: 10px;
height: 10px;
}
23 changes: 11 additions & 12 deletions src/shared/utils/firebase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Loading