-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
48 lines (41 loc) · 1.33 KB
/
firestore.rules
File metadata and controls
48 lines (41 loc) · 1.33 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
41
42
43
44
45
46
47
48
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
function isAdmin() {
return isSignedIn()
&& exists(/databases/$(database)/documents/users/$(request.auth.uid))
&& get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin';
}
// Users can read everyone's public profile, but only edit their own.
// Admins can edit anything.
match /users/{uid} {
allow read: if isSignedIn();
allow create: if isSignedIn() && request.auth.uid == uid
&& request.resource.data.role == 'user';
allow update: if isSignedIn() && (
request.auth.uid == uid
&& request.resource.data.role == resource.data.role // can't self-promote
|| isAdmin()
);
allow delete: if isAdmin();
}
// Events: public read, admin write.
match /events/{slug} {
allow read: if true;
allow write: if isAdmin();
}
// Leaderboard configs: public read, admin write.
match /leaderboards/{id} {
allow read: if true;
allow write: if isAdmin();
}
// Per-user extras (bonus points etc): admin write, everyone read.
match /userExtras/{uid} {
allow read: if true;
allow write: if isAdmin();
}
}
}