-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
30 lines (26 loc) · 870 Bytes
/
firestore.rules
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isSignedIn() {
return request.auth != null;
}
function isOwner(userId) {
return isSignedIn() && request.auth.uid == userId;
}
// Reward transactions
match /reward_transactions/{transactionId} {
allow read: if isSignedIn() &&
request.auth.uid == resource.data.userId;
allow create: if false; // Only through server functions
}
// User credits and achievements
match /users/{userId} {
allow read: if isSignedIn();
allow update: if isOwner(userId) &&
(!request.resource.data.diff(resource.data).affectedKeys()
.hasAny(['credits', 'achievements'])); // Prevent direct credit/achievement updates
}
// Rest of your existing rules...
}
}