ilrock
ilrock

Reputation: 593

Firebase firestore - Data must be an object, but it was: a custom Object object

I'm using Firestore in conjunction with realtime database in order to provide a user presence system for my application.

Update: article I followed

https://blog.campvanilla.com/firebase-firestore-guide-how-to-user-presence-online-offline-basics-66dc27f67802

In one of the methods I use this code here:

const usersRef = this.$fireStore.collection('users').doc(uid)
const whoIsOnlineRef = this.$fireDb.ref('.info/connected')

whoIsOnlineRef.on('value', (snapshot) => {
    this.$fireDb.ref(`/status/${uid}`)
        .onDisconnect()
        .set('offline')
        .then(() => {
          usersRef.set({ online: true }, { merge: true })

          this.$fireDb.ref(`/status/${uid}`).set('online')
        })
})

The .set method, however, is giving me the error mentioned in the title and I can't quite understand why. I'm simply passing a javascript object to .set method and this should technically work.

Can you spot what is wrong with the code?

Upvotes: 2

Views: 1782

Answers (1)

ilrock
ilrock

Reputation: 593

Looks like the reason why this wasn't working is that the code was running on the server in an SSR application.

I moved that very same logic to the browser and it started working nicely. I still don't see why this wouldn't work in the server as, at the end of the day I was still passing a simple js object to the .set() method.

Either way, there you have it

Upvotes: 1

Related Questions