代码之家  ›  专栏  ›  技术社区  ›  Peter Warbo

firebase多路径更新失败,在拒绝权限/

  •  0
  • Peter Warbo  · 技术社区  · 6 年前

    我试图在某些路径(不是根路径(/)上)进行多路径更新,但收到一个警告 @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 回复  |  直到 6 年前
    推荐文章