简体   繁体   English

Firebase 实时数据库规则-auth

[英]Firebase realtime database rule - auth

if my data structure is like the following (example: an array of books)如果我的数据结构如下所示(例如:一系列书籍)

     books: 
           0 :    name = book1,
                    id= 123

           1: name = book2,
                id = 456

           2: name = book3,
                id = 789

how can I grant read and write access in firebase realtime database for the '/books' url?我如何在 firebase 实时数据库中授予 '/books' url 的读写权限? Please note that my 'auth.id' matches the 'id' inside each book.请注意,我的“auth.id”与每本书中的“id”相匹配。

so the data is (books/0/id == auth.id) but the url access to read and write is for '/books'.所以数据是 (books/0/id == auth.id) 但 url 读写权限是针对 '/books' 的。 Is there a way to use the id and grant access at a parent level?有没有办法在父级别使用 id 和授予访问权限?

I tried the following,我尝试了以下,

        "rules"
             "books" 
                  "$id" {".read" : $id == auth.uid} 

but no luck..但没有运气..

Thanks谢谢

Since you are working with arrays, I guess that $id captures just the index.由于您正在使用 arrays,我猜$id只捕获索引。 So, you'd try the following:因此,您将尝试以下操作:

{
  "rules": {
    "books": {
      "$book_index": {
        ".read" : "data.child('id').val() == auth.uid"
      }
    }
  }
}

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

相关问题 Firebase 实时数据库不安全规则警告 - Firebase Realtime Database Insecure Rule Warning 如何在 Firebase 实时数据库规则中将键解析为数字? - How to parse key as a number in a Firebase Realtime Database rule? 如何在 firebase 实时数据库的安全规则中授予对 UID 列表的访问权限 - How to give access to a list of UID in security rule of firebase realtime database Angularfire Firebase 实时数据库类型错误:n.auth 不是 function - Angularfire Firebase realtime database TypeError: n.auth is not a function Firebase 的 UI Auth 是否与实时数据库连接? - Does Firebase's UI Auth connect with Realtime Database? 如何将授权详细信息添加到 firebase 请求以访问实时数据库? - How to add auth details to firebase request to access realtime database? 实时数据库 - Firebase 不更新 - realtime database - Firebase not updating Firebase 实时数据库规则 - Firebase realtime database rules 如何编写 firebase 实时数据库规则以匹配根文件夹子文件夹名称与新数据自定义 uid - how to write a firebase Realtime database rule to match root folder child folders name with New Data custom uid 实时 FireBase 数据库规则 - auth.token 在获取请求中位于何处? - Realtime FireBase Database rules - where is auth.token located in a fetch request?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM