-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase.storage.rules
50 lines (39 loc) · 1.24 KB
/
firebase.storage.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
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /games/{game}/thumbnail {
allow read: if isLoggedIn();
match /{fileName} {
allow get;
allow list: if isLoggedIn();
allow delete: if isLoggedIn() && isFileOwnerAndMemberOrAdmin();
allow create, update: if isLoggedIn() && isFileOwnerAndMemberOrAdmin() && isBellowMaxSize() && isValidContentType();
}
}
function isLoggedIn() {
return request.auth != null;
}
function isAdmin() {
return request.auth.token.admin == true;
}
function isMember() {
return request.auth.token.member == true;
}
function isFileOwner() {
return getResource().metadata.authorUid == request.auth.uid;
}
function isFileOwnerAndMemberOrAdmin() {
return isAdmin() || (isMember() && isFileOwner());
}
function isBellowMaxSize() {
// Only allow uploads of any image file that's less than 5MB
return request.resource.size < 5 * 1024 * 1024;
}
function isValidContentType() {
return request.resource.contentType.matches('image/(png|jpeg)');
}
function getResource() {
return resource == null ? request.resource : resource
}
}
}