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.