问题
I have a collection reviews
where each review contains a list of uid
s of users who have liked it called likes
. The schema looks like:
- review (collection)
- title
string
- author
uid
- likes [
uid
] - posted
timestamp
- title
- user (collection) -
uid
- created
timestamp
- email
string
- created
Currently, I'm handling a user liking a review with:
firebase.firestore().doc(rid).update({
likes: firebase.firestore.FieldValue.arrayUnion(this.fetchCurrentUID())
});
And unliking with:
firebase.firestore().doc(rid).update({
likes: firebase.firestore.FieldValue.arrayRemove(this.fetchCurrentUID())
});
I only want to let a user add or remove their own uid
from likes
.
How can I write a security rule to ensure this? Specifically, I need to see how the list is being updated, for instance something like:
let newVals = request.resource.data.new_values // or something
return (newVals.length == 1 && newVals[0] == request.auth.uid)
来源:https://stackoverflow.com/questions/61528403/see-array-changes-in-firestore-security