-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
34 lines (30 loc) · 1.76 KB
/
firestore.rules
File metadata and controls
34 lines (30 loc) · 1.76 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// ── User-scoped data ─────────────────────────────────────────────────────
// Only the authenticated owner can read/write their own data.
// Uses UID matching (not email) — more secure and cannot be spoofed.
match /users/{userId}/{document=**} {
allow read, write: if request.auth != null
&& request.auth.uid == userId;
}
// ── Daily logs: field-level validation ───────────────────────────────────
match /users/{userId}/daily_logs/{dateKey} {
allow read: if request.auth != null && request.auth.uid == userId;
allow write: if request.auth != null
&& request.auth.uid == userId
// Validate that user_id in document matches the authenticated user
&& (!request.resource.data.keys().hasAny(['user_id'])
|| request.resource.data.user_id == request.auth.uid);
}
// ── Global data: field-level validation ──────────────────────────────────
match /users/{userId}/global_data/{docName} {
allow read: if request.auth != null && request.auth.uid == userId;
allow write: if request.auth != null && request.auth.uid == userId;
}
// ── Deny all other paths ────────────────────────────────────────────────
match /{document=**} {
allow read, write: if false;
}
}
}