-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
36 lines (31 loc) · 886 Bytes
/
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /orders/{id} {
allow read: if true;
//allow read: if isOwner(); // Would restrict reads to just the item owner
allow delete: if isOwner();
allow update: if isOwner() && willBeOwner();
allow create: if willBeOwner();
}
}
// Check if authenticated user has the specified uid
function isUser(uid) {
return request.auth.uid != null && request.auth.uid == uid;
}
// Check if user matches current data owner
function isOwner(){
return isUser(currentData().owner);
}
// Check if user matches potential future data owner
function willBeOwner(){
return isUser(futureData().owner);
}
function currentData() {
return resource.data;
}
// Get future state of data if write were accepted
function futureData() {
return request.resource.data;
}
}