This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Solved : The Read and Write Rules were set to False. I thought I set them to true when I created the project. I am not sure why and how they turned to False again.
So I am just getting started with Firebase. Downloaded the CLI, init a project from a CLI and deployed it to Firebase hosting. However I can't get the .on() function to work for the database neither I can figure out how to read a value from the Database. I have been tried looking at several videos and the documentation and I have no idea whats wrong.
All the code is in the index.html. I do have an entry named object in the Database.
try {
let app = firebase.app();
let features = ['auth', 'database', 'messaging', 'storage'].filter(feature => typeof app[feature] === 'function');
document.getElementById('load').innerHTML = `Firebase SDK loaded with ${features.join(', ')}`;
console.log("This code is working");
//Get elements
const preObject = document.getElementById('object');
console.log(firebase.database());
//Create Reference
const dbRefObject = firebase.database().ref().child('object');
//Sync Object
dbRefObject.on('value', snap => console.log(snap.val()));
firebase.database().ref("object/").on('value',function(snapshot){console.log(snapshot.val());});
} catch (e) {
console.error(e);
document.getElementById('load').innerHTML = 'Error loading the Firebase SDK, check the console.';
}
});
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Firebase/co...