2

I'm creating a e-commerce with Vue & Firebase. Trying to add some cart information from the current logged in user. Strange thing is at the very first time information saved perfectly. When I trying to add some again. That dosent work and show this error.

Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined

So I have to refresh that page. Then it work again. I cant understand where is the problem.

Note: If I try to add any other value instead of cart. then it works fine.

checkoutLoggedInUser(){
  var db = firebase.firestore();           
  var user = firebase.auth().currentUser;

  db.collection("orders").add({
     user_id:user.uid,
     cart:this.$store.getters.cart                    
  })

  this.$store.commit('emptyCart')                
  this.$router.push({ name: 'Home'})
}
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441

1 Answers1

2

That error message is saying that one of the fields you're trying to write to a document is undefined in JavaScript. Check the values that you're passing by using console.log or using a debugger to figure out which one is undefined, then change your code to pass something else, or omit the field entirely.

Also bear in mind that the error message is referencing a call to DocumentReference.set(), but the code you're showing is calling DocumentReference.add(), so the error might be in a different location.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441