-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
72 lines (57 loc) · 2.63 KB
/
firestore.rules
File metadata and controls
72 lines (57 loc) · 2.63 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Snippets collection
match /snippets/{snippetId} {
// Anyone can read public snippets
allow read: if resource.data.isPublic == true;
// Authenticated users can create snippets
allow create: if request.auth != null;
// Only the author can update or delete their snippets
allow update, delete: if request.auth != null && request.auth.uid == resource.data.authorId;
// Authors can read their own private snippets
allow read: if request.auth != null && request.auth.uid == resource.data.authorId;
}
// Users collection
match /users/{userId} {
// Public profiles are readable by anyone
allow read: if true;
// Users can only write to their own profile
allow write: if request.auth != null && request.auth.uid == userId;
}
// Comments collection (nested under snippets)
match /snippets/{snippetId}/comments/{commentId} {
// Anyone can read comments on public snippets
allow read: if get(/databases/$(database)/documents/snippets/$(snippetId)).data.isPublic == true;
// Authors can read comments on their own snippets
allow read: if request.auth != null &&
get(/databases/$(database)/documents/snippets/$(snippetId)).data.authorId == request.auth.uid;
// Authenticated users can create comments
allow create: if request.auth != null;
// Only the comment author can update or delete their comments
allow update, delete: if request.auth != null && request.auth.uid == resource.data.authorId;
}
// Likes collection (for tracking snippet likes)
match /likes/{likeId} {
// Anyone can read likes
allow read: if true;
// Authenticated users can create their own likes
allow create: if request.auth != null &&
request.resource.data.userId == request.auth.uid;
// Users can only delete their own likes
allow delete: if request.auth != null &&
resource.data.userId == request.auth.uid;
}
// User follows collection
match /follows/{followId} {
// Anyone can read follows data
allow read: if true;
// Authenticated users can follow/unfollow
allow create: if request.auth != null &&
request.resource.data.followerId == request.auth.uid;
// Users can only delete their own follows
allow delete: if request.auth != null &&
resource.data.followerId == request.auth.uid;
}
}
}