firebase数据库规则允许读/写特定的用户与特定的信息 [英] firebase database rule allow read/write to specific users with specific info

查看:114
本文介绍了firebase数据库规则允许读/写特定的用户与特定的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的firebase数据库规则如下所示:

  {
rules:{
users:{$ b $$ uid:{
$ b $.read:auth!= null || root.child('users')。child(auth.uid) .child('role')。val()=='teacher',
.write:auth!= null || root.child('users')。child(auth.uid)。 ('role')。val()=='teacher'

}
}
}
}


我的目标如下:
$ b $ ul

  • 每个用户都可以只读/写自己的OWN数据。

  • 只有在名为role的子对象中定义值为teacher的用户才能读取/写入其他所有用户的数据。



    如何达到这个规则设定?

    解决方案


    $ b

      {
    rules :{$ b $users:{
    .read:root.child('users')。child(auth.uid).child('role')。val()=='老师',
    .write:root.child('users')。child(auth.uid).child('role')。val()=='teacher',
    $ uid:{
    .read:auth.uid == $ uid,
    .write:auth.uid == $ uid
    }





    有了这个:




    • 老师对整个用户节点

    • 拥有读写权限
    • 其他用户只有自己的节点才具有读写权限


    My firebase database rule is like the following:

        {
          "rules": {
            "users": {
              "$uid": {
    
                ".read": "auth != null || root.child('users').child(auth.uid).child('role').val() == 'teacher'",
                ".write": "auth != null || root.child('users').child(auth.uid).child('role').val() == 'teacher'"
    
              }
            }
        }
    }
    

    My goal is the following:

    • Every user can read/write their OWN data only.
    • Only users with the value 'teacher' defined in their corresponding child named 'role' can read/write EVERY other users' data.

      How can I achieve this rule setting?

    解决方案

    This seems to be what you're looking for:

    {
      "rules": {
        "users": {
          ".read": "root.child('users').child(auth.uid).child('role').val() == 'teacher'",
          ".write": "root.child('users').child(auth.uid).child('role').val() == 'teacher'",
          "$uid": {
            ".read": "auth.uid == $uid",
            ".write": "auth.uid == $uid"
          }
        }
      }
    }
    

    With this:

    • teachers have read and write permission to the entire users node
    • other users have read and write permission to their own node only

    这篇关于firebase数据库规则允许读/写特定的用户与特定的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
  • 登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆