-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
54 lines (50 loc) · 2.68 KB
/
Copy pathfirestore.rules
File metadata and controls
54 lines (50 loc) · 2.68 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// ── users ──────────────────────────────────────────────────────────────
// Anyone can read a user profile (needed for author display)
// Only the authenticated owner can create or update their own document
match /users/{uid} {
allow read: if true;
allow create: if request.auth != null
&& request.auth.uid == uid;
allow update: if request.auth != null
&& request.auth.uid == uid;
}
// ── comments ───────────────────────────────────────────────────────────
// Anyone can read comments (public blog posts)
// Authenticated users can create comments where uid matches their auth uid
// Only the comment author can delete their own comment
match /comments/{commentId} {
allow read: if true;
allow create: if request.auth != null
&& request.resource.data.uid == request.auth.uid
&& request.resource.data.content is string
&& request.resource.data.content.size() > 0;
allow delete: if request.auth != null
&& resource.data.uid == request.auth.uid;
}
// ── likes ──────────────────────────────────────────────────────────────
// Anyone can read like counts (shown on public blog posts)
// Authenticated users can create/delete their own like documents
// Document ID convention: uid_postId
match /likes/{likeId} {
allow read: if true;
allow create: if request.auth != null
&& request.resource.data.uid == request.auth.uid;
allow delete: if request.auth != null
&& resource.data.uid == request.auth.uid;
}
// ── bookmarks ──────────────────────────────────────────────────────────
// Only the owning user can read/write their bookmarks
// getDoc on a non-existent document: resource is null, so we allow
// authenticated reads unconditionally and let the app filter by uid
match /bookmarks/{bookmarkId} {
allow read: if request.auth != null;
allow create: if request.auth != null
&& request.resource.data.uid == request.auth.uid;
allow delete: if request.auth != null
&& resource.data.uid == request.auth.uid;
}
}
}