-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
40 lines (35 loc) · 1.42 KB
/
Copy pathfirestore.rules
File metadata and controls
40 lines (35 loc) · 1.42 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
39
40
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isAuthenticated() {
return request.auth != null;
}
function isOwner(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
function isDocOwner() {
return isAuthenticated() && request.auth.uid == resource.data.userId;
}
function isValidNote(data) {
return data.userId == request.auth.uid &&
data.title is string && data.title.size() <= 500 &&
data.type in ['note', 'todo', 'event'] &&
(!('content' in data) || (data.content is string && data.content.size() <= 10000)) &&
(!('color' in data) || (data.color is string && data.color.size() <= 50)) &&
(!('isPinned' in data) || data.isPinned is bool) &&
(!('isArchived' in data) || data.isArchived is bool) &&
(!('isTrashed' in data) || data.isTrashed is bool);
}
match /users/{userId} {
allow read: if isOwner(userId);
allow write: if isOwner(userId);
}
match /notes/{noteId} {
allow read: if isAuthenticated() && (resource == null || resource.data.userId == request.auth.uid);
allow create: if isAuthenticated() && isValidNote(request.resource.data);
allow update: if isDocOwner() && isValidNote(request.resource.data);
allow delete: if isDocOwner();
}
}
}