사용자가 채널에 있는지 확인하는 Firebase 규칙이 .exists 또는 .val에서 작동하지 않습니다.

사람

안녕하세요 저는 날씨를 확인하기 위해 firebase 규칙을 만들려고합니다. 사용자가 메시지를 보내는 메시지 채널에 있는지 여부를 확인합니다. 다음은 내 firebase 데이터베이스 구조입니다.

firebase 채널

내 규칙은

    "messages": {
      "$room_id": {
        ".read": "root.child('channels').child($room_id).child('joined').child(auth.uid).val() === true",
        ".validate": "root.child('channels').child($room_id).exists()",

.validate(가) 동안 규칙은 작동 .read하지 않습니다. 조인에서 항목을 삭제하거나 삭제하면 작동 .val() === true하며 .exists(). uid가 조인되고 true로 설정된 경우에만 작동해야합니다.

이것은 내가 사용하는 JS 코드입니다.

const itemsRef = firebase.database().ref('messages').child(this.selectedChannel);
itemsRef.on('value', snapshot => {
        let data = snapshot.val();
        this.messages = Object.entries((data || {})).map(m => {return {id: m[0], user: m[1].user, message: m[1].message}});
})
gso_gabriel

In cases like this, usually, the approach used is to set values for variables - for chat rooms applications, usually the variables used are user, timestamp of access and room_id - so you can validate if they are not empty and add the message altogheter. In your case, you will be using a third different variable to the timestamp, when validating.

Considering that, I believe a good configuration for your verification would be the following - this code is untested and you will need to modify more it for your usage, but I believe it's a good starting point, as a basic model for you.

".read": "root.child('members/'+$room_id+'/'+auth.uid+joined).exists() && !data.exists() && newData.exists()",
// the object to write must have a name, message, and be in the room
".validate": "newData.hasChildren(['user', 'message', 'joined'])",

위의 코드 샘플에서와 같이 확인하려는 모든 값이 있으면 유효성 검사가 수행됩니다. 정식 버전에서이 코드의 예는 공식 문서 에서 액세스 할 수 있습니다 .

액세스를 권장하는 Firebase의 간단한 채팅방의 또 다른 예는 다음 저장소에 있습니다. katowulf / gist : 4741111

정보가 도움이되었는지 알려주세요!

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관