프로젝트 막바지 단계...
기능구현은 왠만큼 했으니 이제는 짜잘한 녀석을 손봐야 겠다.
수정 삭제 기능은 파이어베이스 규칙에서 등록글 아이디 값과 현재 로그인한 유저의 아이디값이 같아야만 가능하게 했다.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if true; /// 누구나 읽을 수 있음
}
match /post/{docid} {
allow read : if true ;
allow create: if request.auth != null; //생성은 로그인한 사람만
allow update,delete: if request.auth.uid == resource.data.uid; //수정삭제는 작성자만 가능
}
}
}
이렇게 하니 기능 구현은 됬다 .
이제 작성자일때만 버튼을 보여주는걸 구현했다.
const db = firebase.firestore();
const storage = firebase.storage();
const auth = firebase.auth()
const user = firebase.auth().currentUser;
console.log(auth);
var 쿼리스트링 = new URLSearchParams(window.location.search)
console.log(쿼리스트링.get('id'))
//url에 숨겨 놨던 id 찾아서 doc() 넣어야함
db.collection('post').doc(쿼리스트링.get('id')).get().then((result) => {
firebase.auth().onAuthStateChanged((user) => {
if (user.uid == result.data().uid) {
// Button 보이기
$("#edit").show();
$("#delete").show();
} else {
// Button 숨기기
$("#edit").hide();
$("#delete").hide();
}
})
+ css 파일 에는
display: none; 으로
}
'개발 일지 > 개발 일지' 카테고리의 다른 글
내일배움캠프 Day 23 (0) | 2022.11.30 |
---|---|
내일배움캠프 Week 4 (0) | 2022.11.28 |
내일배움캠프 Day 19 (0) | 2022.11.25 |
내일배움캠프 Day 18 (0) | 2022.11.24 |
내일배움캠프 Day 17 (0) | 2022.11.23 |