-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfirestore.rules
39 lines (34 loc) · 1.25 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
// Unit test and debug your Rules by downloading and running the Emulator.
// Run `firebase emulators:start --only firestore` in your terminal.
// For details go to : https://github.com/firebase/quickstart-nodejs/tree/master/firestore-emulator/javascript-quickstart
// To deploy rules, run `firebase deploy --only rules` in your terminal.
service cloud.firestore {
match /databases/{database}/documents {
// True if the user is an admin
function isAdmin() {
return request.auth.uid != null && get(/databases/$(database)/documents/admins/$(request.auth.uid)).data.isAdmin;
}
// True if user owns the document
function isOwner(uid){
return request.auth.uid == uid;
}
// True if user is logged in
function isAuthed(){
return request.auth.uid != null
}
match /users/{uid} {
allow read: if isOwner(uid) || isAdmin();
allow write: if isOwner(uid) || isAdmin();
match /goals/{goalId} {
allow read : if isOwner(uid) || isAdmin();
allow delete : if isOwner(uid) || isAdmin();
allow create : if isOwner(uid) || isAdmin();
allow update : if isOwner(uid) || isAdmin();
}
}
match /admins/{uid} {
allow read: if isAdmin();
allow write: if isAdmin();
}
}
}