-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
firestore.rules
121 lines (107 loc) · 4.39 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read: if request.auth != null;
allow create: if request.auth.uid == userId
&& request.resource.data.keys().hasAll(['displayName', 'photoURL', 'joinedAt', 'lastLogin'])
&& request.resource.data.photoURL is string
&& request.resource.data.displayName is string
&& request.resource.data.joinedAt == request.time
&& request.resource.data.lastLogin == request.time
;
allow update: if request.auth.uid == userId
&& request.resource.data
.diff(resource.data)
.affectedKeys()
.hasOnly(['displayName', 'photoURL', 'lastLogin'])
&& request.resource.data.photoURL is string
&& request.resource.data.displayName is string
&& request.resource.data.lastLogin == request.time
;
allow delete: if false;
}
match /users/{userId}/notes/{noteId} {
// only the current user can read their own
allow read: if request.auth.uid == userId;
allow create: if request.auth.uid == userId
&& request.resource.data.size() == 2
&& request.resource.data.createdAt == request.time
&& request.resource.data.content is string
&& request.resource.data.content.size() > 0
&& request.resource.data.content.size() <= 512;
allow delete: if false;
}
match /pixels/{userId} {
allow read;
allow create: if request.auth.uid == userId
&& ['displayName', 'photoURL', 'createdAt', 'content', 'pos', 'revision']
.toSet()
.difference(request.resource.data.keys().toSet())
.size() == 0
&& request.resource.data.photoURL is string
&& request.resource.data.displayName is string
&& request.resource.data.pos is int
&& request.resource.data.createdAt == request.time
&& request.resource.data.revision == 1
&& request.resource.data.content is string
&& request.resource.data.content.size() <= 2
;
allow update: if request.auth.uid == userId
&& ['createdAt', 'content', 'pos', 'revision']
.toSet()
.difference(request.resource.data.keys().toSet())
.size() == 0
&& request.resource.data.createdAt == request.time
// only allow one write every 5 seconds
&& request.time > resource.data.createdAt + duration.value(5, 's')
&& request.resource.data.pos is int
// only allow increments
&& request.resource.data.revision == resource.data.revision + 1
&& request.resource.data.content is string
&& request.resource.data.content.size() <= 2
;
allow delete: if request.auth.uid == userId;
}
match /emojis/{userId} {
allow read;
allow delete: if false;
allow create: if request.auth.uid == userId
&& ['displayName', 'photoURL', 'createdAt', 'content', 'pos', 'revision']
.toSet()
.difference(request.resource.data.keys().toSet())
.size() == 0
&& request.resource.data.photoURL is string
&& request.resource.data.displayName is string
&& request.resource.data.pos is int
&& request.resource.data.createdAt == request.time
&& request.resource.data.revision == 1
&& request.resource.data.content is string
&& request.resource.data.content.size() <= 2
;
allow update: if request.auth.uid == userId
&& ['createdAt', 'content', 'pos', 'revision']
.toSet()
.difference(request.resource.data.keys().toSet())
.size() == 0
&& request.resource.data.createdAt == request.time
// only allow one write every 5 seconds
&& request.time > resource.data.createdAt + duration.value(5, 's')
&& request.resource.data.pos is int
// only allow increments
&& request.resource.data.revision == resource.data.revision + 1
&& request.resource.data.content is string
&& request.resource.data.content.size() <= 2
;
}
match /count/{day} {
allow read;
// only allow writing { when: now timestamp; n: int }
allow write: if request.resource.data.size() == 2 && request.resource.data.when is timestamp && request.resource.data.n is int;
}
// forbid everything else
match /{document=**} {
allow read, write: if false;
}
}
}