-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirestore.rules
More file actions
93 lines (78 loc) · 2.83 KB
/
firestore.rules
File metadata and controls
93 lines (78 loc) · 2.83 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper: check if user is an admin
function isAdmin() {
return request.auth != null &&
exists(/databases/$(database)/documents/adminProfiles/$(request.auth.uid));
}
// Admin Profiles - only admins can read their own profile
match /adminProfiles/{uid} {
allow read: if request.auth != null && request.auth.uid == uid;
allow write: if isAdmin();
}
// User Profiles - users can read/write their own profile, admins can read all
match /userProfiles/{uid} {
allow read, write: if request.auth != null && request.auth.uid == uid;
allow read, write: if isAdmin();
}
// Products - anyone can read active products, only admins can write
match /products/{productId} {
allow read: if resource.data.isActive == true;
allow read, write: if isAdmin();
}
// Collections - anyone can read active, admins write
match /collections/{collectionId} {
allow read: if resource.data.isActive == true;
allow read, write: if isAdmin();
}
// Customers - admin only
match /customers/{customerId} {
allow read, write: if isAdmin();
// Allow creation from public checkout
allow create: if true;
}
// Orders - users can read their own orders, admin can read/write all, public can create
match /orders/{orderId} {
allow read: if request.auth != null && resource.data.customerEmail == request.auth.token.email;
allow read, write: if isAdmin();
allow create: if true;
}
// Order Items - admin only
match /orderItems/{itemId} {
allow read, write: if isAdmin();
allow create: if true;
}
// Coupons - anyone can read active coupons, admins manage
match /coupons/{couponId} {
allow read: if resource.data.isActive == true;
allow read, write: if isAdmin();
}
// Campaigns - anyone can read active, admins manage
match /campaigns/{campaignId} {
allow read: if resource.data.isActive == true;
allow read, write: if isAdmin();
}
// Reviews - anyone can read approved, anyone can create, admins manage
match /reviews/{reviewId} {
allow read: if resource.data.status == 'approved';
allow create: if true;
allow read, write: if isAdmin();
}
// Banners - anyone can read active, admins manage
match /banners/{bannerId} {
allow read: if resource.data.isActive == true;
allow read, write: if isAdmin();
}
// Store Settings - anyone can read, admins write
match /storeSettings/{settingId} {
allow read: if true;
allow write: if isAdmin();
}
// Analytics Events - anyone can create, admins read
match /analyticsEvents/{eventId} {
allow create: if true;
allow read: if isAdmin();
}
}
}