Firebase多路径更新失败,权限在/

时间:2019-01-29 10:36:27

标签: javascript firebase firebase-realtime-database firebase-security-rules

我正在尝试在某些路径(而不是根(/)路径)上进行多路径更新,但是我收到警告@firebase/database: FIREBASE WARNING: update at / failed: permission_denied,然后出现一条错误,提示权限被拒绝。

我已授予指定路径的权限。

很明显,如果我授予root(/)权限,则更新有效。

Index.js:

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'https://' + firebaseId + '.firebaseio.com',
  storageBucket: firebaseId + '.appspot.com',
  databaseAuthVariableOverride: {
    uid: "service-account"
  }
});

规则:

{
  "rules": {
    "users": {
      "$userid": {
        "ownerGameId": {
          ".validate": "newData.isString()",
          ".write": "((data.val() == null && (auth != null && auth.uid == 'service-account')) || ((data.val() != null && newData.val() == null) && (auth != null && auth.uid == 'service-account')))"
        },
        "joinedGameId": {
          ".validate": "newData.isString()",
          ".write": "((data.val() == null && (auth != null && auth.uid == $userid)) || ((data.val() != null && newData.val() == null) && ((auth != null && auth.uid == $userid) || (auth != null && auth.uid == 'service-account'))))"
        },
        "$other": {
          ".validate": "false"
        },
        ".write": "(data.val() == null && (auth != null && auth.uid == $userid))",
        ".read": "((auth != null && auth.uid == $userid) || (auth != null && auth.uid == 'service-account'))"
      }
    },
    "not-started-party-game-locations": {
      ".read": "auth != null",
      ".indexOn": [
        "g"
      ],
      "$id": {
        ".write": "((data.val() == null && (auth != null && auth.uid == 'service-account')) || ((data.val() != null && newData.val() == null) && (auth != null && auth.uid == 'service-account')))"
      }
    },
    "games": {
      "$gameid": {
        "state": {
          ".validate": "newData.hasChildren()",
          ".write": "((data.val() == null && (auth != null && auth.uid == 'service-account')) || ((data.val() != null && newData.val() != null) && (auth != null && auth.uid == 'service-account')))"
        },
        "$other": {
          ".validate": "false"
        },
        ".write": "(data.val() == null && auth != null)",
        ".read": "(auth != null || (auth != null && auth.uid == 'service-account'))"
      }
    }
  }
}

我要执行的更新:

{ '/users/Hoh2t79MplcG7OTq6QqYpn8AbMz1/joinedGameId': null,
  '/users/Hoh2t79MplcG7OTq6QqYpn8AbMz1/ownerGameId': null,
  '/users/hdD48t58FQRhnbHbdwMprrsuB2x2/joinedGameId': null,
  '/users/hdD48t58FQRhnbHbdwMprrsuB2x2/ownerGameId': null,
  '/games/-LXO8cv2v4BLrPnMeuMh/state': { base: 'cancelled' },
  '/not-started-party-game-locations/-LXO8cv2v4BLrPnMeuMh': null }

admin.database().ref().update(updates);

0 个答案:

没有答案