-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfirestore.rules
More file actions
54 lines (45 loc) · 1.99 KB
/
Copy pathfirestore.rules
File metadata and controls
54 lines (45 loc) · 1.99 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 {
// 사용자 문서: 본인만 R/W
match /users/{uid} {
allow read, write: if request.auth != null && request.auth.uid == uid;
}
// baby 문서
match /babies/{babyId} {
// 인증된 사용자만 read (초대 코드 등록 시 baby 존재 확인용)
allow read: if request.auth != null;
// create: 본인이 mainCaregiver이며 caregiverIDs에 본인 포함
allow create: if request.auth != null
&& request.resource.data.mainCaregiverID == request.auth.uid
&& request.auth.uid in request.resource.data.caregiverIDs;
// update: 기존 caregiver이거나, caregiverIDs에 본인 uid 추가만 허용
allow update: if request.auth != null
&& (
request.auth.uid in resource.data.caregiverIDs
|| (
request.resource.data.diff(resource.data).affectedKeys().hasOnly(['caregiverIDs'])
&& request.auth.uid in request.resource.data.caregiverIDs
)
);
// delete: mainCaregiver만
allow delete: if request.auth != null
&& resource.data.mainCaregiverID == request.auth.uid;
// 케어 기록 서브컬렉션: baby caregiver만 R/W
match /records/{recordId} {
allow read, write: if request.auth != null
&& request.auth.uid in get(/databases/$(database)/documents/babies/$(babyId)).data.caregiverIDs;
}
// 울음 분석 기록 서브컬렉션: baby caregiver만 R/W
match /cryRecords/{recordId} {
allow read, write: if request.auth != null
&& request.auth.uid in get(/databases/$(database)/documents/babies/$(babyId)).data.caregiverIDs;
}
// 육아 수첩 노트 서브컬렉션: baby caregiver만 R/W
match /notes/{noteId} {
allow read, write: if request.auth != null
&& request.auth.uid in get(/databases/$(database)/documents/babies/$(babyId)).data.caregiverIDs;
}
}
}
}