-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
31 lines (28 loc) · 1.1 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
function isOwn(uid) {
return isSignedIn() && request.auth.uid == uid;
}
function isNew() {
return resource == null;
}
function documentPath(paths) {
return path(['databases', database, 'documents'].concat(paths).join('/'));
}
match /threads/{threadId} {
allow read: if isOwn(resource.data.uid);
allow create: if isOwn(request.resource.data.uid) && existsAfter(documentPath(['threadContents', threadId]));
allow delete: if isOwn(resource.data.uid) && !existsAfter(documentPath(['threadContents', threadId]));
}
match /threadContents/{threadId} {
allow get: if (isSignedIn() && isNew()) || isOwn(resource.data.uid);
allow create: if isOwn(request.resource.data.uid) && existsAfter(documentPath(['threads', threadId]));
allow update: if isOwn(resource.data.uid);
allow delete: if isOwn(resource.data.uid) && !existsAfter(documentPath(['threads', threadId]));
}
}
}