-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.rules
More file actions
56 lines (48 loc) · 1.63 KB
/
storage.rules
File metadata and controls
56 lines (48 loc) · 1.63 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
49
50
51
52
53
54
55
56
rules_version = '2';
// Firebase Storage Security Rules for JournalXP
service firebase.storage {
match /b/{bucket}/o {
// Helper function to check if user is authenticated
function isAuthenticated() {
return request.auth != null;
}
// Helper function to check if user owns the resource
function isOwner(userId) {
return request.auth.uid == userId;
}
// Helper function to validate image file
function isValidImage() {
return request.resource.size < 5 * 1024 * 1024 // Max 5MB
&& request.resource.contentType.matches('image/.*');
}
// Profile Pictures
// Path: profilePictures/{userId}
// Users can upload/update/delete their own profile picture
match /profilePictures/{userId} {
allow read: if true; // Anyone can view profile pictures
allow write: if isAuthenticated()
&& isOwner(userId)
&& isValidImage();
}
// Community/Post Images (if needed in the future)
// Path: communityImages/{userId}/{imageId}
match /communityImages/{userId}/{imageId} {
allow read: if true; // Public read
allow write: if isAuthenticated()
&& isOwner(userId)
&& isValidImage();
}
// Pet Images (if needed in the future)
// Path: petImages/{userId}/{imageId}
match /petImages/{userId}/{imageId} {
allow read: if true; // Public read
allow write: if isAuthenticated()
&& isOwner(userId)
&& isValidImage();
}
// Default: Deny all other access
match /{allPaths=**} {
allow read, write: if false;
}
}
}