gdg-tangier / vue-firestore

:cloud: Cloud Firestore binding in realtime with Vuejs
MIT License
235 stars 28 forks source link

Reject on onSnapshot error #4

Closed Jaimeer closed 6 years ago

Jaimeer commented 6 years ago

Please can you add reject in onSnapshot error in functions "collections" and "documents" to be able to detect for example "permission-denied" errors

Thanks

amranidev commented 6 years ago

Thanks for submitting this issue!!

The bind function already returns a promise, you can simply trigger that manually.

  this.$binding("users", firebase.firestore().collection("users"))
  .then((users) => {
    console.log(users) // => __ob__: Observer
  }).catch(error) => {
      console.error(error.message)
  }
Jaimeer commented 6 years ago

Hi, that only works if the problem is with the docChanges.forEach

source.onSnapshot(doc => {
    doc.docChanges.forEach(snapshot => {
      ...
    }, error => {
          reject(error)
        })
  })
}

You should add a new reject in onSnapshot

source.onSnapshot(doc => {
    doc.docChanges.forEach(snapshot => {
      ...
    }, error => {
          reject(error)
        })
  }, error => { // <-- New reject
          reject(error)
        })
}

The same for the documents

source.onSnapshot(doc => {
   ...
  }, error => { // <-- New reject
          reject(error)
        })

You can test it trying to access a collection in firestore where you don't have permissions

Regards @

Jaimeer commented 6 years ago

Without the extra reject if you try the next code and receive an "Error: Missing or insufficient permissions.":

component
      .$binding('tests', firebase.db.collection('tests'))
      .then(tests => {
        ...
      })
      .catch(error => {
        // Not enter
      })

Regards

amranidev commented 6 years ago

Fixed!! Thanks :+1: