-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud.firestore.rules
42 lines (33 loc) · 1.05 KB
/
cloud.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
// resource only exists when reading from DB
// request.resource only exists when writing to DB (reading from the user)
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /games/{game} {
allow read: if true;
allow create, update, delete: if isLoggedIn() && isMemberAndDocumentOwnerOrAdmin()
}
match /tags/{tag} {
allow read: if true;
allow create, update, delete: if isLoggedIn() && isMemberAndDocumentOwnerOrAdmin()
}
function isLoggedIn() {
return request.auth != null;
}
function isDocumentOwner() {
return getResourceData().authorUid == request.auth.uid;
}
function isAdmin() {
return request.auth.token.admin == true;
}
function isMember() {
return request.auth.token.member == true;
}
function isMemberAndDocumentOwnerOrAdmin() {
return isAdmin() || (isMember() && isDocumentOwner());
}
function getResourceData() {
return resource == null ? request.resource.data : resource.data
}
}
}