-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
58 lines (48 loc) · 1.78 KB
/
firestore.rules
File metadata and controls
58 lines (48 loc) · 1.78 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
57
58
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper function to check if user is authenticated
function isAuthenticated() {
return request.auth != null;
}
// Helper function to check if user has admin/super role
// NOTE: This assumes custom claims are set OR we check a user document.
// Since custom claims are better for security but require backend setup,
// we'll check the 'authors' collection for role as per the app's structure.
function isAdmin() {
return isAuthenticated() &&
exists(/databases/$(database)/documents/authors/$(request.auth.uid)) &&
(get(/databases/$(database)/documents/authors/$(request.auth.uid)).data.role in ['admin', 'super']);
}
// Default: Deny all
match /{document=**} {
allow read, write: if false;
}
// Articles: Public read, Admin write
match /articles/{articleId} {
allow read: if true;
allow write: if isAdmin();
}
// News: Public read, Admin write
// Removed as part of News functionality removal
// Authors/Team: Public read, Admin write (or self update - optional)
match /authors/{userId} {
allow read: if true;
allow write: if isAdmin() || (isAuthenticated() && request.auth.uid == userId);
}
// Assets: Authenticated users can read/write
match /assets/{assetId} {
allow read: if isAuthenticated();
allow write: if isAuthenticated();
}
// Meta (Stats): Authenticated users can read
match /meta/{docId} {
allow read: if isAuthenticated();
allow write: if isAdmin();
}
// Asset Index: Authenticated users can read (for search/stats)
match /assets_index/{docId} {
allow read: if isAuthenticated();
}
}
}