如何允许特定用户访问firebase节点?

如何允许特定用户访问firebase节点?,firebase,firebase-security,Firebase,Firebase Security,我想允许所有登录的用户访问创建新内容,但只有所有者才能更新数据。我不知道怎么做,这是我尝试过的: { "rules": { ".read": false, ".write": false, "videos": { ".read": true, ".indexOn": ["id", "title_lower_case"], "$video": { ".write": "(auth !== null &&

我想允许所有登录的用户访问创建新内容,但只有所有者才能更新数据。我不知道怎么做,这是我尝试过的:

{
  "rules": {
    ".read": false,
    ".write": false,
    "videos": {
      ".read": true,
      ".indexOn": ["id", "title_lower_case"],
      "$video": {
        ".write": "(auth !== null && auth.provider === 'password' && (!newData.exists() || newData.hasChildren())) || (auth.uid === root.child('videos').child($video).child('uid').val())",
        ".validate": "newData.hasChildren(['id', 'title', 'title_lower_case', 'uid'])",
        "id": {
          ".validate": "newData.isString() && newData.val().length >= 5 && newData.val().length <= 1000"
        },
        "title": {
          ".validate": "newData.isString() && newData.val().length >= 2 && newData.val().length <= 1000"
        },
        "title_lower_case": {
          ".validate": "newData.isString() && newData.val().length >= 2 && newData.val().length <= 1000"
        },
        "uid": {
          ".validate": "newData.val() === auth.uid"
        },
        "$other": {
          ".validate": false
        }
      }
    },
    "users": {
      ".read": true,
      "$user": {
        ".read": "auth !== null && auth.provider === 'password'",
        ".write": "auth.uid === $user && (!newData.exists() || newData.hasChildren())",
        ".indexOn": "name_lower_case",
        ".validate": "newData.hasChildren(['email', 'name', 'name_lower_case'])",
        "email": {
          ".validate": "newData.isString() && newData.val().length <= 2000"
        },
        "name": {
          ".validate": "newData.isString() && newData.val().length >= 2 && newData.val().length <= 2000"
        },
        "name_lower_case": {
          ".validate": "newData.isString() && newData.val().length >= 2 && newData.val().length <= 2000"
        },
        "$other": {
          ".validate": false
        }
      }
    }
  }
}
此部分仅允许所有者编辑节点:

auth.uid === root.child('videos').child($video).child('uid').val()

顺便说一句,如果有什么要说的,我会在firebase中使用简单的登录功能。

执行下面的操作似乎就可以了。如果auth变量存在,则允许写入功能。由于我没有完全理解这些规则,我不得不怀疑这是针对当前用户运行的,还是在检查是否有用户登录

{
    "rules": {
      "product":{
        ".read": true,
        ".write":"auth !== null"
      }
    }
}

但这只检查你是否登录,而不是你是否是“视频”的所有者,对吗?
{
    "rules": {
      "product":{
        ".read": true,
        ".write":"auth !== null"
      }
    }
}