从 Firebase 检索网络数据不起作用



我正在尝试使用多种方式读取和显示Firebase数据库中的数据,但无法使其正常工作。 我的火力基地有以下结构: 火碱数据库

这是整个js代码:

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);
});
});

控制台.log不显示任何内容。

注意:我已经尝试使用"child_added"而不是"值",但它不起作用。

问题是我的数据库上的规则不允许从任何来源读取/写入。

最新更新