-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfirestore.rules
50 lines (41 loc) · 1.41 KB
/
firestore.rules
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 {
function emailIsVerified() {
return request.auth.token.email_verified == true;
}
function chatExists(chatUid) {
return exists(/databases/$(database)/documents/chats/$(chatUid));
}
function littenExists(littenUid) {
return exists(/databases/$(database)/documents/littens/$(littenUid));
}
function isAuthenticated() {
return request.auth != null;
}
function isSameUser(userUid) {
return request.auth.uid == userUid;
}
match /chats/{chatUid} {
allow create: if isAuthenticated() && littenExists(request.resource.data.littenUid);
allow read, update, delete: if isAuthenticated();
}
match /littens/{littenUid} {
function isLittenOwner() {
return request.auth.uid == resource.data.userUid;
}
allow create: if isAuthenticated() && emailIsVerified();
allow read: if isAuthenticated();
allow update, delete: if isAuthenticated() && isLittenOwner();
}
match /messages/{messageUid} {
allow create: if isAuthenticated() && chatExists(request.resource.data.chatUid);
allow read, delete: if isAuthenticated();
allow update: if false
}
match /users/{userUid} {
allow create, read: if isAuthenticated();
allow update, delete: if isAuthenticated() && isSameUser(userUid);
}
}
}