0

Im trying to delete data from firebase. I am logged into the VueJS host application, and have the firebase rules set as below, but it is still giving me a permission denied error. The commented out code gives the same result.

Rules:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write, delete: if true;
    }
  }
}

Function:

test(trackID) {
            console.log(firebase.auth().currentUser.uid)
            var usersRef = firebase.database().ref(`users/${firebase.auth().currentUser.uid}/tracks/${trackID}`)
            // let usersRef = db.collection('users').doc(`${firebase.auth().currentUser.uid}/tracks/${trackID}`)
            usersRef.remove().then(() => {
            // usersRef.delete().then(() => {
                console.log('Document successfully deleted!')
            }).catch(function(error) {
                console.error('Error removing document: ', error)
            })
        },

Console:

Account.vue?e7d7:82 Error removing document:  Error: PERMISSION_DENIED: Permission denied
at eval (index.cjs.js?3523:13076)
at exceptionGuard (index.cjs.js?3523:690)
at Repo.callOnCompleteCallback (index.cjs.js?3523:13067)
at eval (index.cjs.js?3523:12844)
at eval (index.cjs.js?3523:12019)
at PersistentConnection.onDataMessage_ (index.cjs.js?3523:12052)
at Connection.onDataMessage_ (index.cjs.js?3523:11337)
at Connection.onPrimaryMessageReceived_ (index.cjs.js?3523:11331)
at WebSocketConnection.eval [as onMessage] (index.cjs.js?3523:11232)
at WebSocketConnection.appendFrame_ (index.cjs.js?3523:10837)
bcooley1983
  • 172
  • 3
  • 12
  • 2
    Your JS is referencing the realtime database and your rules are firestore. Which one are you trying to use? – Jack Woodward Dec 06 '18 at 12:58
  • The security rules you're showing apply to Cloud Firestore, while the code you're showing is accessing the Realtime Database. While both databases are part of Firebase, they're completely separate, and the security for one don't apply to the other. To fix the error, you will have to set the rules for the Realtime Database. For a walkthrough of how to do that, see https://stackoverflow.com/a/52129163 – Frank van Puffelen Dec 06 '18 at 14:31

0 Answers0