-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
50 lines (44 loc) · 2.12 KB
/
Copy pathfirestore.rules
File metadata and controls
50 lines (44 loc) · 2.12 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper: is user authenticated?
function isAuthed() {
return request.auth != null;
}
// Helper: is the requesting user a participant in the room?
function isParticipant(roomId) {
return isAuthed() &&
exists(/databases/$(database)/documents/rooms/$(roomId)/presence/$(request.auth.uid));
}
match /rooms/{roomId} {
// ── Messages ──────────────────────────────────────────────────
match /messages/{messageId} {
// Authenticated users in the room can read messages
allow read: if isParticipant(roomId);
// Only write your own messages (userId must match auth uid)
allow create: if isAuthed()
&& request.resource.data.userId == request.auth.uid
&& request.resource.data.text is string
&& request.resource.data.text.size() >= 1
&& request.resource.data.text.size() <= 500;
// Score preview updates are allowed (Edge Function uses Admin SDK; client limited)
allow update: if isAuthed()
&& resource.data.userId == request.auth.uid;
}
// ── Presence ──────────────────────────────────────────────────
match /presence/{userId} {
// Anyone authenticated can read presence to see who's online
allow read: if isAuthed();
// Users can only write their own presence document
allow write: if isAuthed() && request.auth.uid == userId;
}
// ── Typing Indicators ─────────────────────────────────────────
match /typing/{userId} {
// Room participants can read typing indicators
allow read: if isParticipant(roomId);
// Users can only write their own typing document
allow write: if isAuthed() && request.auth.uid == userId;
}
}
}
}