0
votes

I'm trying to read and show the data from my Firebase Database using many ways but could not get it work. I've the following structure in my firebase : Firebase database

And this is the entire js code:

var config = {
    apiKey: "thecharactersoftheapikey",
    authDomain: "xyxyxyxyxyxyxy.firebaseapp.com",
    databaseURL: "https://xxxxxxxxxxx.firebaseio.com",
    projectId: "xyxyxyxyxy",
    storageBucket: "xxxxxxxxxx.appspot.com",
    messagingSenderId: "12345678"
  };
  firebase.initializeApp(config);

/*If user is logged or Not and get the user email to display*/ 
firebase.auth().onAuthStateChanged(function(user) {
    var name, email, picture;
    if (user) {
            name = user.displayName;
            uid = user.uid;
            email = user.email;
            //picture = user.photoURL;
            //document.getElementById("user-image").src = picture;
            document.getElementById("user-name").innerHTML = email;
    }else {
        document.getElementById("members-area").style.display="none";
    }
  });

  /*To Log out */
function singOut(){
    firebase.auth().signOut().then(function() {
    // Sign-out successful.
    location.href="http://localhost/xxx/index.html";
  }).catch(function(error) {
    // An error happened.
  });  
}


/*Retrieving data from the database*/ 
var usersRef = firebase.database().ref('users');
     usersRef.on('value', function(snapshot)  {
     snapshot.forEach(function(childSnapshot) {
      var childData = childSnapshot.val();
      console.log(childData);
     });
    });

The console.log don't display anything.

Note: I already tried using "child_added" instead of "value" and it does not work.

1
Please do console.log(snapshot.val()) before the foreach loop - Saksham Gupta
I did it and nothing happened. console.log is not displaying any value. - HAM
Did you hook your app up to your firebase? - Joseph Webber
@heagma Can you show your entire JavaScript code? - Renaud Tarnec
I did hook the app as I have an user and I can show the data of the user but when using the database, I can not read any data. I'll update the post and put the entire code - HAM

1 Answers

0
votes

The issue was the rules on my database were not allowing read/write from any source.