-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
storage.rules
33 lines (27 loc) · 950 Bytes
/
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
service firebase.storage {
match /b/{bucket}/o {
// PUBLIC RULES
match /public/{imageId} {
// only allow public file to be uploaded
// with this pattern `pdfun-1245515151515.pdf`
allow write: if imageId.matches("pdfun-.*\\.pdf");
// only allow public resized files to be read
// with this pattern `RESIZE-pdfun-1245515151515.pdf`
allow read: if imageId.matches("RESIZE-pdfun-.*\\.pdf") || imageId.matches("PASSWORD_REMOVAL-pdfun-.*\\.pdf") || imageId.matches(".*\\.zip");
}
// PRIVATE RULES
match /users/{userId} {
allow read, write: if isOwner(userId) || isAdmin();
match /pdfs/{pdfId} {
allow read, write: if isOwner(userId) || isAdmin();
}
}
// HELPERS FUNCTIONS
function isOwner(userId) {
return request.auth != null && request.auth.uid == userId;
}
function isAdmin() {
return request.auth.token.admin == true;
}
}
}