-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfirestore.rules
42 lines (38 loc) · 1.06 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
function userId() {
return request.auth.uid;
}
function ownsItem() {
return userId() == existingData().owner.id;
}
function accessesField(field) {
return incomingData().diff(existingData()).affectedKeys().hasOnly([field]);
}
// [READ] Data that exists on the Firestore document
function existingData() {
return resource.data;
}
// [WRITE] Data that is sent to a Firestore document
function incomingData() {
return request.resource.data;
}
match /tasks/{task} {
allow read: if isSignedIn();
allow create: if isSignedIn() && userId() == incomingData().owner.id;
allow update: if isSignedIn() && ownsItem();
allow delete: if isSignedIn() && ownsItem();
}
match /users/{user} {
allow read: if true;
allow write: if false;
}
match /{document=**} {
allow read, write: if false;
}
}
}