-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
38 lines (35 loc) · 1.63 KB
/
Copy pathfirestore.rules
File metadata and controls
38 lines (35 loc) · 1.63 KB
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
function isSignedIn() { return request.auth != null; }
function incoming() { return request.resource.data; }
function existing() { return resource.data; }
function isValidNote(data) {
return data.keys().hasAll(['userId', 'title', 'content', 'createdAt', 'updatedAt'])
&& data.keys().size() == 5
&& data.userId == request.auth.uid
&& data.title is string && data.title.size() <= 200
&& data.content is string && data.content.size() <= 50000
&& data.createdAt is timestamp
&& data.updatedAt is timestamp;
}
match /notes/{noteId} {
allow read: if isSignedIn() && existing().userId == request.auth.uid;
// allow list must check resource.data to secure the data
allow list: if isSignedIn() && resource.data.userId == request.auth.uid;
allow delete: if isSignedIn() && existing().userId == request.auth.uid;
allow create: if isSignedIn()
&& isValidNote(incoming())
&& incoming().createdAt == request.time;
allow update: if isSignedIn()
&& existing().userId == request.auth.uid
&& incoming().diff(existing()).affectedKeys().hasOnly(['title', 'content', 'updatedAt'])
&& incoming().updatedAt == request.time
&& incoming().title is string && incoming().title.size() <= 200
&& incoming().content is string && incoming().content.size() <= 50000;
}
}
}