nuxt-community / firebase-module

🔥 Easily integrate Firebase into your Nuxt project. 🔥
https://firebase.nuxtjs.org
MIT License
641 stars 98 forks source link

[Firestore] invalid-argument on addDoc() call with serverTimestamp #397

Closed Flawe closed 3 years ago

Flawe commented 3 years ago

I'm trying to add a new Firestore document in asyncData, which may be wrong to begin with, but perhaps someone can help me figure out what's happening here in case this should be working.

This is basically the call:

async asyncData(context) {
  const res = await context.app.$fire.firestore.collection('items').add({
    created: context.app.$fireModule.firestore.FieldValue.serverTimestamp(),
  })
}

And the result:

Error [FirebaseError]: Function addDoc() called with invalid data. Data must be an object, but it was: a custom Object object (found in document items/umQdLWadRdLjFxbG2cpc)> 
    at new FirestoreError (.../node_modules/@firebase/firestore/dist/index.node.cjs.js:266:28)
    at createError (.../node_modules/@firebase/firestore/dist/index.node.cjs.js:22270:12)
    at ParseContext.createError (.../node_modules/@firebase/firestore/dist/index.node.cjs.js:21828:16)
    at validatePlainObject (.../node_modules/@firebase/firestore/dist/index.node.cjs.js:22195:27)
    at parseSetData (.../node_modules/@firebase/firestore/dist/index.node.cjs.js:21885:5)
    at addDoc (.../node_modules/@firebase/firestore/dist/index.node.cjs.js:22546:18)
    at CollectionReference$1.add (.../node_modules/@firebase/firestore/dist/index.node.cjs.js:25005:16)
    at asyncData (pages/items.js:270:75) {
  code: 'invalid-argument',
  toString: [Function (anonymous)]
}

It seems like the sentinel object for the timestamp isn't liked by the api. Is there a different way to achieve this?

Flawe commented 3 years ago

Dupe of #116