1
votes

I'm having an issue with a Firestore observer and it's associated rules. I'm trying to have rules that only allow the user to see invites that contain the user's email address. However, if I delete a document from the collection, the snapshot observer throws an error Uncaught Error in onSnapshot: FirebaseError: Null value error. for 'get' @ L92.

Here's my rules:

 match /invites/{inviteID} {

      function isSignedIn() {
        return request.auth != null;
      }

      function isUserInvite() {
        return request.auth.token.email != null &&
        request.auth.token.email == resource.data.user_email;
      }

      allow read: if isSignedIn() && isUserInvite();
      allow write: if true;

}

And here's my listener.

firebase.firestore()
.collection("invites")
.where(`user_email`, '==', myUserEmail) // this would be the users email
.onSnapshot((snapshot) => {

  snapshot.forEach( doc => {
    console.log(doc.id, doc.data())
  })

})

It works for observing new documents, but fails when deleting a document. The following code makes the observer throw an error.

// creates a new invite and the snapshot listener informs me 
await firebase.firestore()
.collection('invites')
.doc("invite_1")
.set({
  user_email: someUserEmail, // use the users email here 
  date_added: firebase.firestore.FieldValue.serverTimestamp()
})

// deletes the invite, but the snapshot throws an error
await firebase.firestore()
.doc(`invites/invite_1`)
.delete()

UPDATE

I've found that this is only happening in the firestore emulator and not in production. Both the emulator and production have the same rules.

1
Could you edit the question to be more specific about what you're doing? In particular, you should say which document you're deleting, and what you expect to happen instead with the snapshot listener. - Doug Stevenson
Hey there. Updated the question. I don't expect the listener to throw an error and stop working (which is what it's currently doing). I would think listener should just return a new set of results without the deleted document. - JoeBayLD
@DougStevenson Updated again. Sorry if there wasn't enough clarity at first. Turns out the issue is only happening when using the emulator. I'm going to keep digging and see if I can find why that's the case. - JoeBayLD
If it's only with the emulator, then it might be a bug, and you should file it here: github.com/firebase/firebase-tools - Doug Stevenson
@JoshLyon I did. Just answered my own question on here. Google has fixed the bug! :) - JoeBayLD

1 Answers

2
votes

After submitting a bug report to Google - they confirmed it was a bug that only applied to the emulator. This was fixed in a new release. Here’s a link to the GitHub issue for any needed reference.

https://github.com/firebase/firebase-tools/issues/2197