-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
95 lines (76 loc) · 2.92 KB
/
firestore.rules
File metadata and controls
95 lines (76 loc) · 2.92 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// ========================================
// HELPER FUNCTIONS
// ========================================
// Check if user is authenticated
function isAuthenticated() {
return request.auth != null;
}
// Check if user owns the document
function isOwner(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
// Check if user is an admin/owner
function isOwner() {
return isAuthenticated() &&
(request.auth.token.email == 'info@defrag.app' ||
request.auth.token.email == 'chadowen93@gmail.com');
}
// Check if user has paid
function hasPaid() {
return isAuthenticated() &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.paymentVerified == true;
}
// ========================================
// USER PROFILES
// ========================================
match /users/{userId} {
// Users can read their own profile
// Owners can read all profiles
allow read: if isOwner(userId) || isOwner();
// Users can create/update their own profile
// Owners can create/update any profile
allow create, update: if isOwner(userId) || isOwner();
// Only owners can delete profiles
allow delete: if isOwner();
}
// ========================================
// RELATIONSHIP MANUALS
// ========================================
// Rule for the new metadata collection
match /manual_metadata/{manualId} {
allow read, write: if request.auth != null && request.auth.uid == resource.data.userId;
allow create: if request.auth != null && request.auth.uid == request.resource.data.userId;
}
// Existing rule for full manuals
match /manuals/{manualId} {
allow read, write: if request.auth != null && request.auth.uid == resource.data.userId;
allow create: if request.auth != null && request.auth.uid == request.resource.data.userId;
}
// ========================================
// ADMIN COLLECTIONS
// ========================================
match /admin/{document=**} {
allow read, write: if isOwner();
}
// ========================================
// ANALYTICS & LOGS (Read-only for owners)
// ========================================
match /analytics/{document=**} {
allow read: if isOwner();
allow write: if false; // Writes handled server-side only
}
match /logs/{document=**} {
allow read: if isOwner();
allow write: if false; // Writes handled server-side only
}
// ========================================
// DENY ALL OTHER ACCESS
// ========================================
match /{document=**} {
allow read, write: if false;
}
}
}