Search code examples
firebasevue.jsfirebase-authenticationgoogle-cloud-firestorevuefire

Getting "undefined" in "this" inside firestore in vuefire


I'm using firebase-auth and firebase-firestore in my Vue application, with vuefire to retrieve the user data from firestore.

So, I have in my instance:

data() {
  return {
      user: firebase.auth().currentUser
  }
},
firestore: {
  userData: db.collection("users").where("uid", "==", this.user.uid)
}

But when the code is executed, "this", which should be the instance of Vue, is undefined. How can I solve this?


Solution

  • I stuck into the same problem, have no idea why this is undefined. As a workaround you can use Programmatic binding in created hook like this:

      created() {
        this.$bind('userData', db.collection("users").where("uid", "==", this.user.uid))
      },