Firebase安全规则与通配符 [英] Firebase security rules with wildcards

查看:213
本文介绍了Firebase安全规则与通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数据结构:



如何在Firebase安全规则中访问 / Restaurant / -KK37k6g5cYYippEHpZ3 / User / -KK37k6g5cYYippEHpZ4 / id 的值?两个按键应该是通配符。我需要这样的:

 Restaurant:{
$ id:{
.read:auth.uid!= null,
.write:data.child($ id).child('User')。child($ anotherWildcard).child('id') .val()=== auth.uid

}


解决方案

不知道我是否完全理解你所要求的,但这里是我的想法。



你的规则的第一个问题是你正在指定 child($ id),但你已经在 $ id 内。它隐含在你引用的 data $ id



要解决你的主要问题,你不需要另一个通配符。您可以使用 hasChild 来验证 auth.uid 是否位于 restaurant / user

 Restaurant:{
$ id:{
.read:auth.uid!= null,
.write:auth.uid!= null&& amp; data.child('User')。hasChild(auth.uid)
}
}


I've got a data structure like this:

How can I access /Restaurant/-KK37k6g5cYYippEHpZ3/User/-KK37k6g5cYYippEHpZ4/id's value within the firebase security rules? The two push keys should be wildcards. I need something like this:

"Restaurant": {
        "$id": {
            ".read": "auth.uid != null",
            ".write": "data.child($id).child('User').child($anotherWildcard).child('id').val() === auth.uid"  
        }
    }

解决方案

Not sure if I fully understood what you are asking for but here goes my thoughts.

The first problem in your rule is that you are specifying child($id) but you already are inside the $id. it is implicit in your data that you are referring to $id.

To resolve your main problem you wont need another wildcard. You can just use hasChild to verify if the auth.uid is inside restaurant/user.

"Restaurant": {
   "$id": {
      ".read": "auth.uid != null",
      ".write": "auth.uid != null && data.child('User').hasChild(auth.uid)"
   }
}

这篇关于Firebase安全规则与通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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