1
votes

RULES FILES

   {
      "rules": {
        ".write": true,
        "users": {
          ".validate": "newData.hasChildren(['uuid', 'on'])",
          "on": {
            ".validate": "newData.isNumber() &&
                          newData.val() >= 0 &&
                          newData.val() <= 1"
          },
          "uuid": {

          }
        }
      }
    }

this is my code (node.js).

firebase.initializeApp({
    serviceAccount: "BITCOIN-f9a190c06e27.json",
    databaseURL: "https://bitcoin-865ac.firebaseio.com"
});



var users = firebase.database().ref('/users')


    users.set({
        uuid: 'xxxx',
        on: '0'

    });

I have this mistake.

FIREBASE WARNING: set at /users failed: permission_denied (node:444) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: PERMISSION_DENIED: Permission denied

i dont have any idea, i thought the write "true", was enough to give any permissions

3

3 Answers

1
votes

Add read also:

"rules": {
    ".read": true,
    ".write": true
0
votes

Just delete all database rules add this in database rules. then I would try to clean the code

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

In your code ".read": true is missing

0
votes

with "users" node this is a simple user auth rules that can work:

{
 "rules": {
  "users": {
    ".read": "false",
    ".write": "true",
  "$uid": {
    ".read": "auth.uid === $uid",
    ".write": "auth.uid === $uid"
    }
   }
  }
}