-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
48 lines (41 loc) · 1.76 KB
/
Copy pathfirestore.rules
File metadata and controls
48 lines (41 loc) · 1.76 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// ── Users ──
// Anyone authenticated can read user profiles (needed for search by uniqueId).
// Only the owner can write their own profile.
match /users/{userId} {
allow read: if request.auth != null;
allow write: if request.auth != null && request.auth.uid == userId;
// ── Contacts subcollection ──
// Only the owner can read/write their own contacts.
match /contacts/{contactId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
// ── Conversations ──
// Participants can read and write their own conversations.
// Creation is allowed for any authenticated user (both participants are set at creation).
match /conversations/{convoId} {
allow create: if request.auth != null;
allow read, update: if request.auth != null
&& request.auth.uid in resource.data.participants;
// ── Messages subcollection ──
// Participants of the parent conversation can read/write messages.
match /messages/{messageId} {
allow read, write: if request.auth != null
&& request.auth.uid in get(/databases/$(database)/documents/conversations/$(convoId)).data.participants;
}
}
// ── Groups (if using group chat) ──
match /groups/{groupId} {
allow create: if request.auth != null;
allow read, update: if request.auth != null
&& request.auth.uid in resource.data.members;
match /messages/{messageId} {
allow read, write: if request.auth != null
&& request.auth.uid in get(/databases/$(database)/documents/groups/$(groupId)).data.members;
}
}
}
}