react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

Unable to fetch data from firebase but can save data to firebase

Open Oshianor opened this issue 8 years ago • 17 comments

Issue

Environment

  1. Application Target Platform:
both
  1. Development Operating System:
windows 10
  1. Build Tools:
Android Studio
  1. React Native version:
0.55
  1. React Native Firebase Version:
4.3.8
  1. Firebase Module:
database, auth, core
  1. Are you using typescript?
no

Loving react-native-firebase? Please consider supporting them with any of the below:

Oshianor avatar Aug 15 '18 22:08 Oshianor

Whenever i run this code i get no response unless am just starting the android dev server . Even when i reload my app it still doesnt work. firebase.database().ref('post').once('value').then(res => console.log(res))

screenshot 27 screenshot 28 screenshot 29 screenshot 30

Oshianor avatar Aug 15 '18 22:08 Oshianor

Can we see your code usage please? Those screenshots don't really help sorry!

But, failure to read data on both platforms to me would indicate that this is perhaps an issue with your database rules on the Firebase consoles - check your rules, the default ones, for example, require a user to be authenticated.


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Ehesp avatar Aug 17 '18 08:08 Ehesp

My database rules are well setup. After much testing i think i understand what the problem is but i have no ideal how to fix it. Whenever i start up my react native android server when my screens are loaded some times they fetch the data while others they don't and that point i have to manually close the app and open it again. NOTE : The android server keeps running while i close the app.

Oshianor avatar Aug 17 '18 23:08 Oshianor

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 14 '18 23:09 stale[bot]

@Ehesp I seem to also be running into the same issue. I am trying to run the same code as @Oshianor but unless I close the application on my emulator and open it again, the code only executes once and never executes again upon subsequent refreshes.

I am running on [email protected] and [email protected]

Any ideas?

armanatz avatar Sep 27 '18 19:09 armanatz

having the same issue here. Didn't have this problem when using web based firebase npm

KennethSJiang avatar Sep 29 '18 14:09 KennethSJiang

Same issue here, I have to restart the app and emulator in order for the .on() listener to fire.

Im running [email protected] and [email protected]

csgonutty avatar Oct 03 '18 10:10 csgonutty

I was going to report the same issue. React Native Firebase works, but then on Android after a few JS reloads it stops working.

I'm using react-redux-firebase, however I did include this code in my app to verify that this issue is actually in react-native-firebase and not in react-redux-firebase:

firebase.firestore().collection('practice').get()
	.then(data => console.log(data.docs[0].data()))
	.catch(console.error);

Of particular note. I notice that when it's working I get data; when it fails I get no response at all. i.e. It does not fail with an error, it simply never resolves the promise.

And it doesn't start working again until I force quit the app and reopen it.

dantman avatar Oct 10 '18 21:10 dantman

The same issue here. Database works on the first load but stops working after dev app refreshes. I observed this issue after updating to RNFIrebase v5.0.0

kamicodaxe avatar Oct 22 '18 16:10 kamicodaxe

I have got the same problem. I need to reload whole app to receive the data on componentDidMount

gitsad avatar Oct 23 '18 13:10 gitsad

Hey all, this should be fixed as part of https://github.com/invertase/react-native-firebase/pull/1619 - you can give it a go on [email protected] - see the rc1 release notes on GH for the correct Native SDK versions.

For firestore could you please raise a seperate issue so I can track it and work on it there.


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Salakar avatar Oct 27 '18 04:10 Salakar

same here still

tzurae avatar Mar 11 '19 08:03 tzurae

I'am having the same problem. I was using the latest react-native-firebase version but then i read that downgrading to 5.2.0 solves the problem. It Solves it until syntax error, once i fix my bundling problem firebase database stops working... I'm using react-native 0.59.2 On windows 10 and developing for android

silvafacundo avatar Mar 27 '19 00:03 silvafacundo

@silvafacundo I have the same problem but with "react-native-firebase": "4.3.8", and I think the syntax is true,

displayCategories = () => {
    const refData = firebase.database().ref("categories");
    var items = [];
    refData.once("value", snapshot => {
      console.log(snapshot.val());
      snapshot.forEach((childSnapshot) => {
        items.push({
          id: childSnapshot.val().id,
          name: childSnapshot.val().name,
        });
      });
      this.setState({ categories: items })
    });
  }

if you solve the problem please tell me!

anastely avatar Mar 28 '19 17:03 anastely

@silvafacundo I have the same problem but with "react-native-firebase": "4.3.8", and I think the syntax is true,

displayCategories = () => {
    const refData = firebase.database().ref("categories");
    var items = [];
    refData.once("value", snapshot => {
      console.log(snapshot.val());
      snapshot.forEach((childSnapshot) => {
        items.push({
          id: childSnapshot.val().id,
          name: childSnapshot.val().name,
        });
      });
      this.setState({ categories: items })
    });
  }

if you solve the problem please tell me!

@anastely I think that the problem is coming from Debuggin JS Remotely. I've managed to get it working by not using that option. Debbugin is pretty tedious, but that was the only solution I've could find

silvafacundo avatar Mar 28 '19 17:03 silvafacundo

@silvafacundo uh oh, it's work after uninstalling the app and stoped Debugging JS Remotely, but now it's not real-time after delete or insert data I don't see any update on my app and change the .once into .on , any idea?

anastely avatar Mar 28 '19 17:03 anastely

@anastely Uhmmm... for me it's working fine, make sure that you are updating the correct path, and that is updating at console.firebase.google.com. If it isn't updating, catch for errors of all your firebase database references and check your database rules. If you want attach your files and database structure and rules so I can have a better idea

silvafacundo avatar Mar 28 '19 18:03 silvafacundo