I'm tunning a query for data that may not exist . When this is the case, the callback is not run. As I understand from the docs, it should run and the snapshot.val() should be null, isn't it?
There's a stripped down example here: http://surfmaps.eu/trombone/case.html
There's a console.log inside the callback that is not executed.
Am I missing something here?
Bye and thanks, Luís
Code:
function getData(id) {
var ref=firebase.database().ref("support/"+id);
console.log("In getData, looking for ",ref);
// get support data from firebase
ref.on('value',function (snapshot) {
console.log("In Value");
console.log(snapshot);
});
console.log("end getData, looking for ",ref);
}
// on startup
getData("abc");
You don't have permission to read the data. To see this, you can attach a completion listener and log the error it gives you:
var ref=firebase.database().ref("support/"+id);
console.log("In getData, looking for ",ref);
// get support data from firebase
ref.on('value',function (snapshot) {
console.log("In Value");
console.log(snapshot);
}, function(error) {
console.error(error);
});
console.log("end getData, looking for ",ref);
Doing so shows:
Error: permission_denied at /support/abc: Client doesn't have permission to access the desired data.
See Firebase Rules, You dont have permission to Access Firebase Database Collection.
Go to Firebase Console, Database, Rules to update:
{
"support{
".read": true, // allow read
".write": false
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With