I am trying to create a document reference, set up an onsnapshot listener, save the document and then upload a file which will trigger a cloud function which will make updates to the document i am listening to. But onSnapshot
gives a permissions error of 'FirebaseError: Missing or insufficient permissions.'
after the snapshot has run once (I guess for the initial state).
I have tried running simulations of accessing and writing the data in the firebase console and it works without any errors
const db = window.firebase.firestore()
const newBaseRef = db.collection('base').doc()
newBaseRef.onSnapshot(doc => {
console.log('Current data: ', doc.data())
}, function (error) {
throw error // THIS ALWAYS GETS HIT
})
newBaseRef.set({
uid: window.firebase.auth().currentUser.uid,
createdAt: window.firebase.firestore.FieldValue.serverTimestamp()
})
here are my security rules
service cloud.firestore {
match /databases/{database}/documents {
match /printset/{document=**} {
allow read, update, delete: if request.auth.uid == resource.data.uid
allow create: if request.auth.uid != null;
}
match /file/{document=**} {
allow read, update, delete: if request.auth.uid == resource.data.uid
allow create: if request.auth.uid != null;
}
match /base/{document=**} {
allow read, update, delete: if request.auth.uid == resource.data.uid
allow create: if request.auth.uid != null;
}
}
}
I dont expect the error callback to run
match /base/{baseId}/{document=**}
.match /base/{document==**}
should work. But i wonder. Also.doc()
seems to be empty, Is that intentional? – Philip