-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
61 lines (51 loc) · 1.94 KB
/
Copy pathfirestore.rules
File metadata and controls
61 lines (51 loc) · 1.94 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper function to check if requesting user has role "staff" or "admin"
function isStaffOrAdmin() {
return request.auth != null &&
exists(/databases/$(database)/documents/users/$(request.auth.uid)) &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role in ['staff', 'admin'];
}
// Users collection:
// - Authenticated users can read their own document, or staff/admin can read any user document
// - Authenticated users can create their own document on signup
// - Only staff/admin can update roles or delete user documents
match /users/{userId} {
allow read: if request.auth != null && (request.auth.uid == userId || isStaffOrAdmin());
allow create: if request.auth != null && request.auth.uid == userId;
allow update, delete: if isStaffOrAdmin();
}
// Orders collection:
// Public read & public write (customers can create/view orders without authentication)
match /orders/{orderId} {
allow read, write: if true;
}
// Inventory collection:
// Public read (menu needs to show live availability)
// Write restricted to users with role "staff" or "admin"
match /inventory/{itemId} {
allow read: if true;
allow write: if isStaffOrAdmin();
}
// Staff-only collections:
// Restricted to users with role "staff" or "admin"
match /analytics/{docId} {
allow read, write: if isStaffOrAdmin();
}
match /staff/{docId} {
allow read, write: if isStaffOrAdmin();
}
match /bills/{docId} {
allow read, write: if isStaffOrAdmin();
}
match /tables/{docId} {
allow read: if true;
allow write: if isStaffOrAdmin();
}
// Default fallback rule for any unspecified collection: staff/admin only
match /{document=**} {
allow read, write: if isStaffOrAdmin();
}
}
}