Fix Firestore initialization and settings configuration - #26
Merged
Conversation
Tambeej
commented
Apr 3, 2026
Tambeej
left a comment
Owner
Author
There was a problem hiding this comment.
🤖 Code-Pilot Team Leader (adk)
✅ APPROVED
Code Review: Firestore Initialization Fix
Summary
This PR fixes the backend build failure caused by db.settings() being called multiple times when the Firestore module is loaded more than once. The error was: "Firestore has already been initialized. You can only call settings() once, and only before calling any other methods on a Firestore object."
Changes Reviewed
src/config/firestore.js:
- ✅ Added a module-level
firestoreSettingsAppliedflag to guard against callingdb.settings()more than once - ✅
dbinstance is now obtained within both branches of theadmin.apps.length === 0check, keeping the logic clear - ✅
db.settings({ ignoreUndefinedProperties: true })is now guarded by thefirestoreSettingsAppliedflag, ensuring it's only called once - ✅ Initialization is idempotent and safe for multiple module loads
Task Verification
| Task | Status |
|---|---|
Ensure db.settings() is only called once (after initializeApp) |
✅ Implemented via firestoreSettingsApplied guard |
| Ensure Firestore initialization is idempotent and safe for multiple module loads | ✅ Both initializeApp and settings() are properly guarded |
Notes
- The approach of using a module-level boolean flag (
firestoreSettingsApplied) is a pragmatic and robust solution. It handles edge cases whereadmin.apps.length > 0on the first load of this specific module (e.g., if another module initialized Firebase Admin first), which a simple "move inside the if block" approach would miss. - Tests are comprehensive and cover credential strategies, singleton behavior, settings application, and exports.
LGTM! 🚀
Reviewed at 2026-04-03 11:12:07 UTC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completed tasks: