-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
45 lines (37 loc) · 1.43 KB
/
Copy pathfirestore.rules
File metadata and controls
45 lines (37 loc) · 1.43 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 {
// Helper functions
function isAuthenticated() {
return request.auth != null;
}
function isOwner(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
// Users collection
match /users/{userId} {
// Anyone authenticated can read user profiles
allow read: if isAuthenticated();
// Only the user can create/update/delete their own profile
allow create: if isOwner(userId);
allow update: if isOwner(userId);
allow delete: if isOwner(userId);
}
// Groups collection
match /groups/{groupId} {
// Anyone authenticated can read groups
allow read: if isAuthenticated();
// Any authenticated user can create a group (Relaxed for debugging)
allow create: if isAuthenticated();
// Only creator or admins can update the group
allow update: if isAuthenticated()
&& (resource.data.creatorId == request.auth.uid
|| request.auth.uid in resource.data.admins);
// allow update: if isAuthenticated();
// Only creator can delete the group
allow delete: if isAuthenticated()
&& resource.data.creatorId == request.auth.uid;
// allow delete: if isAuthenticated();
}
}
}