本文介绍了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
如何达到这个规则设定?
解决方案
$ b
$ 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数据库规则允许读/写特定的用户与特定的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-14 19:59