-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
31 lines (25 loc) · 1.02 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function signedIn() {
return request.auth != null && request.auth.uid != null;
}
function belongsTo(resource) {
return request.auth.uid == resource.data.userId;
}
function whoami(resource) {
// If the folder id is null, then this
return resource.data.folderId == null || (exists(/databases/$(database)/documents/folders/$(resource.data.folderId)) && get(/databases/$(database)/documents/folders/$(resource.data.folderId)).data.userId == request.auth.uid)
}
match /files/{fileId}{
allow list, read: if signedIn() && belongsTo(resource);
allow create: if signedIn() && belongsTo(request.resource) && whoami(request.resource);
allow update, delete: if false;
}
match /folders/{folderId} {
allow list, read: if signedIn() && belongsTo(resource);
allow create: if signedIn() && belongsTo(request.resource);
allow update, delete: if false;
}
}
}