--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/62854b03-5991-4e2b-90da-ad8af9fbd757%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to fireba...@googlegroups.com.
const collection = 'things'
const userId = firebase.auth().currentUser.uid
firebase.firestore().collection(collection).get().then(snapshot => { // your existing logic firebase.firestore().collection('users').doc(userId) .collection('operationCounts').doc(collection).update({reads: firebase.firestore.FieldValue.increment(snapshot.docChanges().length)}) })
match /{collection}/{document} { allow read: if get(/databases/$(database)/documents/users/$(request.auth.uid)/operationCounts/$(collection)).data.reads
< get(/databases/$(database)/documents/users/$(request.auth.uid)/operationLimits/$(collection)).data.reads}What about something like this:When your user reads documents, increment a counter in the database e.g. (for snapshots)const collection = 'things'
const userId = firebase.auth().currentUser.uidfirebase.firestore().collection(collection).get().then(snapshot => {// your existing logicfirebase.firestore().collection('users').doc(userId).collection('operationCounts').doc(collection).update({reads: firebase.firestore.FieldValue.increment(snapshot.docChanges().length)})})
In firestore rules:match /{collection}/{document} {allow read: if get(/databases/$(database)/documents/users/$(request.auth.uid)/operationCounts/$(collection)).data.reads
< get(/databases/$(database)/documents/users/$(request.auth.uid)/operationLimits/$(collection)).data.reads}I have tried this and it works. As soon as the reads value in /users/{userId}/operationCounts/things exceeds the reads value in /users/{userId}/operationLimits/things an error is throw for insufficient permissions. No background functions needed just values in the database and clever rules.
Maybe also have a scheduled function that resets the operation limits values to 0 every so oftenHope this is helpful.Regards,Paul
On Tuesday, October 1, 2019 at 7:25:40 AM UTC+1, Rui Faria wrote:- onRead function trigger- context.auth.token in function triggersIn my case i use one firestore account to provide services to my customers that have their accounts, and i need to control them individually.if i have any type of problem or excessive use by a customer i cannot suspend all firestore account and block all the customers.In most cases i use live queries and i cannot replace by generic google functions or api in the middle.Using custom tokens,onWrite function trigger and security roles i have the control of writes.without onRead function triggers i cannot have the control of the reads.using onRead Triggers/auth.token we developers can have a more detailed control of reads implement read counters and block access to regions/cities or even IPsusing onRead triggers we developers can sleep well without afraid of huge bills that can kill our businessPlease help me pushing firestore to implement:- onRead function trigger- context.auth.token in function triggersRui Faria
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/cfbdc1e7-5a49-4094-b480-2283f30884b4%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to fireba...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/e874fbe8-8466-4011-99f5-ec6440a0a5c3%40googlegroups.com.
Hi Joaqim,This feature is not likely to come to Firestore in the near future. Maybe you could use Firestore's StackDriver monitoring integration to detect abnormal read/write volume?- Sam
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/e874fbe8-8466-4011-99f5-ec6440a0a5c3%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/96635314-db3e-4d0e-883a-d52544f12878%40googlegroups.com.