Repository navigation
Expand file tree
/
Copy pathfirestore.rules
More file actions
45 lines (41 loc) · 1.82 KB
/
Copy pathfirestore.rules
File metadata and controls
45 lines (41 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Recipes collection - root level
// Anyone authenticated can read recipes
// Only the author can create/delete their own recipes
match /recipes/{recipeId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.resource.data.authorId == request.auth.uid;
// Note: Updates to denormalized averageRating/likes are no longer needed
// as they are calculated on-the-fly via subqueries.
allow update: if request.auth != null
&& resource.data.authorId == request.auth.uid;
allow delete: if request.auth != null
&& resource.data.authorId == request.auth.uid;
// Reviews subcollection under recipes
// Anyone authenticated can read reviews
// Users can only create reviews with their own userId
// Users can only update/delete their own reviews
match /reviews/{reviewId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.resource.data.userId == request.auth.uid;
allow delete: if request.auth != null
&& resource.data.userId == request.auth.uid;
}
}
// Likes collection - root level (bookmarks)
// Anyone authenticated can read likes
// Users can only create likes with their own userId
// Users can only delete their own likes
match /likes/{likeId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.resource.data.userId == request.auth.uid;
allow delete: if request.auth != null
&& resource.data.userId == request.auth.uid;
}
}
}