简体   繁体   中英

Firebase 9 : Realtime database permission denied

Im making a chat app with vue3 and firebase 9, everything works except the delete function. it shows on the console:

@firebase/database: FIREBASE WARNING: set at /message/-MzxBJXezscUw4PbEAys failed: permission_denied

This is my security rules in firebase realtime database

{
   "rules": {
       "messages": {
           ".read": "auth != null",
           ".write": "auth != null"
       }
   }
}

Delete Message Method:

deleteMessage(key) {
  remove(db, `messages/${key}`)
}

HTML:

<div class="chat-delete-wrapper" v-if="msg.userUID == user.uid"> 
   <button class="delete-btn" @click="deleteMessage(msg.id)">
      <i class='bx-fw bx bxs-trash'></i>
   </button>
</div>

How can i fix this and delete the message?

You need to be more specific, as the following snippet.

{
    "rules": {
        ".write": false,
        "messages": {
            "$message": {
                ".read": "auth != null",
                ".write": "auth != null"
            }
        },
        ".read": false
    }
}

See https://firebase.google.com/docs/database/security/core-syntax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM