-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirestore.rules
More file actions
67 lines (57 loc) · 2.59 KB
/
firestore.rules
File metadata and controls
67 lines (57 loc) · 2.59 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// User profiles
match /users/{userId} {
allow read: if request.auth != null;
allow write: if request.auth != null && request.auth.uid == userId;
}
// Challenge progress
match /progress/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
// Rooms — any authenticated user can read (public listing + joining).
// Private room filtering is handled client-side; the query itself
// filters on isPublic so private rooms won't appear in browse results.
match /rooms/{roomId} {
allow read: if request.auth != null;
// Anyone signed in can create (must set themselves as owner)
allow create: if request.auth != null &&
request.auth.uid == request.resource.data.ownerId;
// Owner and editors can update
allow update: if request.auth != null &&
(request.auth.uid == resource.data.ownerId ||
request.auth.uid in resource.data.editorIds);
// Only owner can delete
allow delete: if request.auth != null &&
request.auth.uid == resource.data.ownerId;
// Chat messages subcollection
match /messages/{messageId} {
// Read: authenticated + (group chat OR participants array check OR
// regex fallback for legacy messages without participants field)
allow read: if request.auth != null &&
(resource.data.conversationId == 'group' ||
('participants' in resource.data &&
request.auth.uid in resource.data.participants) ||
(!('participants' in resource.data) &&
resource.data.conversationId.matches('.*' + request.auth.uid + '.*')));
// Create: authenticated + senderId must match the caller's UID +
// for DMs, sender must be a participant
allow create: if request.auth != null &&
request.resource.data.senderId == request.auth.uid &&
(request.resource.data.conversationId == 'group' ||
request.auth.uid in request.resource.data.participants);
// Update/delete: only the original sender
allow update, delete: if request.auth != null &&
resource.data.senderId == request.auth.uid;
}
// Conversation metadata subcollection
match /conversations/{conversationId} {
allow read: if request.auth != null &&
request.auth.uid in resource.data.participants;
allow create, update: if request.auth != null &&
request.auth.uid in request.resource.data.participants;
}
}
}
}