-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore-rules
executable file
·47 lines (40 loc) · 1.04 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{uid} {
allow read, write: if isUser(uid);
}
match /items/{id} {
allow read: if true;
//allow read: if isOwner(); // If you'd like to restrict reads
allow delete: if isOwner();
allow update: if isOwner() && willBeOwner();
allow create: if willBeOwner();
}
}
}
// Helper functions that simplify our rules
// Check if user has the specified uid
function isUser(uid) {
return isSignedIn() && request.auth.uid == uid;
}
// Check if user is signed in
function isSignedIn() {
return request.auth.uid != null;
}
// Check if user matches current data owner
function isOwner(){
return isUser(currentData().owner);
}
// Check if user matches future data owner (if write completes)
function willBeOwner(){
return isUser(incomingData().owner);
}
// Get data being read
function currentData() {
return resource.data;
}
// Get data being written (merged with current data)
function incomingData() {
return request.resource.data;
}