Skip to content

[🐛] Modular initializeFirestore() doesn't support non-default databases #8456

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

Open
1 of 10 tasks
zeevl opened this issue Apr 7, 2025 · 3 comments · May be fixed by #8489
Open
1 of 10 tasks

[🐛] Modular initializeFirestore() doesn't support non-default databases #8456

zeevl opened this issue Apr 7, 2025 · 3 comments · May be fixed by #8489
Labels
impact: web-implementation An API in RNFB does not conform to the Firebase Web SDK Needs Attention plugin: firestore Firebase Cloud Firestore type: enhancement Implements a new Feature

Comments

@zeevl
Copy link

zeevl commented Apr 7, 2025

Issue

🔥

Attempting to do this:

    import {initializeFirestore} from '@react-native-firebase/firestore';

    const db = await initializeFirestore(
      this.app,
      {
        persistence: true,
      },
      'some-other-database'
    );

initializes the db but it still talks to the (default) database.

See TODO here:

// TODO(exaby73): implement 2nd database once it's supported

(not bothering with the rest of the details as it should be pretty obvious from the code, but let me know if you'd like it nonetheless. :))


Project Files

Javascript

Click To Expand

package.json:

    "@react-native-firebase/app": "^21.13.0",
    "@react-native-firebase/auth": "^21.13.0",
    "@react-native-firebase/dynamic-links": "^21.13.0",
    "@react-native-firebase/firestore": "^21.13.0",
    "@react-native-firebase/functions": "^21.13.0",
    "@react-native-firebase/storage": "^21.13.0",

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 5.4.3
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/N & VERSION


@mikehardy
Copy link
Collaborator

Good one - what happens if you locally patch:

export async function initializeFirestore(app, settings /* databaseId */) {
  // TODO(exaby73): implement 2nd database once it's supported
  const firebase = getApp(app.name);
  const firestore = firebase.firestore();
  await firestore.settings.call(firestore, settings, MODULAR_DEPRECATION_ARG);
  return firestore;
}

to be

export async function initializeFirestore(app, settings, databaseId) {
  const firebase = getApp(app.name);
  const firestore = firebase.firestore(settings, databaseId);  // I think this will send it through to the constructor?
  await firestore.settings.call(firestore, settings, MODULAR_DEPRECATION_ARG);
  return firestore;
}

? seems like the natural implementation - something like that should work - we need to get the databaseId sent in to the old namespaced constructor for it to take effect, I'm just not sure what params need to go in front of it for it to work correctly

dub-lin referenced this issue Apr 7, 2025
- note that you still need the packager started, auth tests use a continueUrl
  that hits 8081, and tests will fail if the port refuses connection
@MichaelVerdon MichaelVerdon added plugin: firestore Firebase Cloud Firestore type: enhancement Implements a new Feature and removed type: bug New bug report labels Apr 8, 2025
@mikehardy mikehardy added the impact: web-implementation An API in RNFB does not conform to the Firebase Web SDK label Apr 8, 2025
@zeevl
Copy link
Author

zeevl commented Apr 8, 2025

doing (without settings):

const firestore = firebase.firestore(databaseId); 

worked great!

Happy to do a PR but I expect you'll want tests with it? Unfortunately, that'd be beyond my available capacity atm..

@zeevl zeevl linked a pull request Apr 24, 2025 that will close this issue
8 tasks
@jorebel
Copy link

jorebel commented Apr 25, 2025

When is this going to be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact: web-implementation An API in RNFB does not conform to the Firebase Web SDK Needs Attention plugin: firestore Firebase Cloud Firestore type: enhancement Implements a new Feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@mikehardy @zeevl @MichaelVerdon @jorebel and others