Home > Mobile >  Firebase 9 : Realtime database permission denied
Firebase 9 : Realtime database permission denied

Time:04-06

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  v-if="msg.userUID == user.uid"> 
   <button  @click="deleteMessage(msg.id)">
      <i class='bx-fw bx bxs-trash'></i>
   </button>
</div>

How can i fix this and delete the message?

CodePudding user response:

Your rule is for the path messages, but your error message says you're trying to write to message.

{
   "rules": {
       "messages": {
           ".read": "auth != null",
           ".write": "auth != null"
       }
   }
}
set at /message/-MzxBJXezscUw4PbEAys failed: permission_denied

CodePudding user response:

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

  • Related