Reputation: 1968
I have a collection of data, say, products
and two different set of users merchants
and users
. How do I grant read write access to merchants on products
and only read access to users
?
match /users/{userId} {
allow read: if request.auth.uid == userId;
}
The above rule only defines access for a single users.
Upvotes: 0
Views: 40
Reputation: 3642
Starting point:
match /users/{userId} {
allow read: if request.auth.uid == userId;
}
match /products/{productid} {
// Anyone authenticated can read
allow read: if request.auth.uid != null;
// Only merchants can write
allow write: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.type == 'merchant'
}
Assuming users have field type
with possible values ['user', 'merchant']
More info here
Upvotes: 1