0
votes

Everything is working great except when I try to write to my database. The web page reads and deletes successfully.

Both read and write rules are set to true. this is how I set up firebase:

<script>

   // Initialize Firebase
   var config = {
      apiKey: "AIzaSyA5fulcW9C8xxmo5UeeS3khTrYCW4yMpKI",
      authDomain: "some-app.firebaseapp.com",
      databaseURL: "https://some-app.firebaseio.com",
      projectId: "some-app",
      storageBucket: "some-app.appspot.com",
      messagingSenderId: "870590230527"
   };

   firebase.initializeApp(config);


</script>

And here is the app.js file. There are 3 attempts at writing data to the database which all failed. Nothing was added and no errors were returned. The reading and deleting works fine which means that I have firebase set up correctly. The set() attempt is straight from the Firebase docs. I only want to add a new entry in "articles" with a generated ID, which has a title, author, and text property. That's it.

var database = firebase.database();


firebase.database().ref('articles/' + randKey.toString()).set({
        title: title_,
        author: author_,
        text: text_
});
1
How do you set your Firebase config? - MT-FreeHK
There's too much going on here: a query, multiple attempts to write, and some potentially irrelevant retrieval of values from the HTML. Can you reproduce the problem in a single, standalone piece of code of no more than a dozen lines or so. The standalone part is key here, since that allows any of us to simply copy/paste your code to (try to) reproduce the problem. Also see how to create a minimal, complete, verifiable example - Frank van Puffelen
Just updated the question. Should be clearer now. - Noor
try using firebase.database.ref(...).set(...).then(ok => console.log("worked")).catch(console.error) and see what happens - ThatBrianDude
I added your promise and it did not catch any errors. I played around with it and no errors are returned at all. The set() is working according to Firebase, but with no additions or changes to the database. - Noor

1 Answers

0
votes

Should not have posted this before testing because the set() is working and what was crashing it was title_, author_, and text_ which did not contain String values.