I am using Stripe for payments. For this, I have the following data model in Firestore:
Users/{userId}/payments/{document}
each {document}
is an object that looks like:
{
amount: 55
token: {...}
charge: {...}
}
Users must be able to to write the token
field (this is what gets passed to the server), but I don't want users to be able to write the charge
field.
Currently my rules allow any user to read and write to this document:
match /payments/{documents} {
allow read, write: if request.auth.uid == userId;
}
What Firestore Rules will achieve my desired security?
I believe something along the following would work, it allows clients to update fields except for charge, as well as create documents that don't have the charge field.