firebase-tools:
8.2.0
Platform:
macOS
When deleting a document that has a query on a user auth property, the following error is throw on the snapshot listener. The goal is to observe all invites that has the users email. It works properly when in production, just not in the emulator.

Using these 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 this basic funciton to observe the collection.
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()) // log the invites that belong to the user
})
})
Also have a stack overflow question started: https://stackoverflow.com/questions/61567689/firestore-onsnapshot-rules-throw-error-when-deleting-document
// 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()
The snapshot should always return the query - not throw an error because an item was deleted.
The error FirebaseError: Null value error. for 'get' @ L91 is thrown.
@yuchenshi this seems to be an emulator-only issue with clear reproduction steps, could you take a look?
This seems a lot like https://github.com/firebase/firebase-js-sdk/issues/2967 where @pfiadDi reported a similar symptom. This may be a bug in the Firestore Emulator.
Another repro and instructions (credits to @pfiadDi): https://github.com/pfiadDi/firestore-snapshot-bug
I use parcelJS to pack it (since parcel builds the files into a folder called
distI set the public folder at firebase init todist). So after you build it withparcel index2.htmlyou can close the parcel dev server again and start the emulators:
- open the page
- login
- add data with a click on "Click to add data"
- delete one doc with a click on "This deletes doc1"
The error is caught in the snapshot function and logged in the console.
I can now reproduce this against the Firestore emulator and I have a smaller repro that does not use Firebase Auth. Let me dig more into the the Firestore emulator to see why rules are evaluated that way.
Fix coming in the next release.
Fixed by @yuchenshi in #2259 and will be included in the next release
Most helpful comment
Fix coming in the next release.