invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.74k stars 2.22k forks source link

🔥Can't access other databases in the same project after update #2677

Closed wallstar closed 5 years ago

wallstar commented 5 years ago

Issue

Passing database a url value for a second database is resulting in the following error - "Error: "firebase.database(app)" arg expects a FirebaseApp instance or undefined.

Ensure the arg provided is a Firebase app instance; or no args to use the default Firebase app."

Old Code Which Worked Below const dealsRef = city == 'newOrleans' ? firebase.database().ref('deals') : firebase.database(database).ref('deals');

New Code Which Does Not Work Below const dealsRef = city == 'newOrleans' ? database().ref('deals') : database(cityDatabase).ref('deals');

Imported As import database from '@react-native-firebase/database';

Thanks so much! This library is awesome and I couldn't do what I do without it.

Project Files

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // 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? - [X] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS Mojave 10.14.4 CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz Memory: 301.48 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 12.3.1 - /usr/local/bin/node Yarn: 1.16.0 - /usr/local/bin/yarn npm: 6.9.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0 Android SDK: API Levels: 23, 26, 28 Build Tools: 28.0.3 System Images: android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom IDEs: Android Studio: 3.4 AI-183.5429.30.34.5452501 Xcode: 11.0/11A420a - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.1 => 0.61.1 npmGlobalPackages: create-react-native-web-app: 0.1.14 react-native-cli: 2.0.1 ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [X ] **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:** - 6.0.0 - **`Firebase` module(s) you're using that has the issue:** - Database - **Are you using `TypeScript`?** - `N`


Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

wallstar commented 5 years ago

Solution: Initialize new app. firebase.initializeApp( { databaseURL: yourUrl, apiKey: 'yourKey', appId: 'yourId', messagingSenderId: 'yourSenderId', projectId: 'yourId', storageBucket: 'yourBucket/' }, {name: city} ) const newDatabase = firebase.app(city);

      const dealsRef = city == 'newOrleans' ? database().ref('deals') : database(newDatabase).ref('deals');