简体   繁体   English

Firebase 基于特定数据的实时数据库规则

[英]Firebase Realtime Database Rules Based On Specific Data

Is it possible to set up data access rules for a Realtime Database property based on a specific piece of data that the user is requesting?是否可以根据用户请求的特定数据为实时数据库属性设置数据访问规则?

For example, I'm an authenticated user (using Firebase Authentication), and I'm querying a certain property from the database, like this:例如,我是经过身份验证的用户(使用 Firebase 身份验证),我正在从数据库中查询某个属性,如下所示:

firebase.ref('myLists').orderByChild('listId').equalTo('someString').on('value', (snapshot) => {
  // ...
})

In what ways can I use that 'someString' value in Database Rules?我可以通过哪些方式在数据库规则中使用该'someString'值?

For .write , we have access to data and newData , but I don't think there is something similar for .read ?对于.write ,我们可以访问datanewData .read类似的东西?

You can allow this query, and only this query, by checking:您可以通过检查允许此查询,并且仅允许此查询:

".read": "query.orderByValue === 'listId' && query.equalTo === 'someString'"

Of course this will still only return nodes that have a listId property with a someString value.当然,这仍然只会返回具有listId属性和someString值的节点。

Also see the Firebase documentation on securely querying data .另请参阅有关安全查询数据的 Firebase 文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM