簡體   English   中英

自定義Firebase安全規則

[英]Custom Firebase Security Rule

需要做什么?

  • 每個人都可以閱讀項目。
  • 每個登錄的人都可以將項目寫入數據庫。
  • 每個人都可以使用其uid作為作者來編輯項目。
  • 通過密碼(不是twitter ...)登錄的用戶是主持人,可以編輯所有項目。

數據庫:

{ 
    items: [ 
        {
            title: "some title",
            content: "voila, some content",
            author: {
               uid: "FSDF-SDFSDF-SDFS-SFZE"
            }
        }, {
            title: "some second title title",
            content: "voila, some other content",
            author: {
               uid: "1234-234235-2342-2342"
            }
        }
    ]
}

規則:

"items": {
  ".read": true,
  ".write": "auth !== null",

    "$item": {
        ".read": true,
        ".write": "auth !== null && auth.provider === 'password' or root.child('items/' + $item +  '/author/uid').val() === auth.uid"
    }
}

怎么了?

您可以使用newData服務器變量來獲取author.uid屬性。 然后使用它來對auth.uid進行檢查。

"items": {
  ".read": true,
  "$item": {
    ".write": "newData.child('author/uid').val() === auth.uid || auth.provider === 'password'"
  }
}

您也有單詞or表達式,而不是||

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM