2016-08-01 58 views
1

我正在使用Firebase & iOS並嘗試驗證用戶何時嘗試提交評論。Firebase驗證規則不起作用

這裏是我的規則:

{ 
    "rules": { 
    "comments": { 
     ".read": true, 
     ".write": "auth.uid != null", 
     "$comment_id": { 
     ".validate": "newData.isString() && newData.val().length < 100" 
     } 
    } 
    } 
} 

這裏是我的數據庫結構: enter image description here

已成功發佈是當我刪除了".validate"部分的註釋。我也試過在$comment_id區塊之外放置".validate": "newData.isString() && newData.val().length < 100",但這仍然導致失敗。

無論如何,我從模擬器這個錯誤,當我嘗試添加評論: enter image description here

爲什麼不是我的工作".validate"?我錯過了什麼?

回答

1

您的數據路徑是/comments/$comment_id/comment。您的驗證規則不適合那裏最後的comment

{ 
    "rules": { 
    "comments": { 
     ".read": true, 
     ".write": "auth.uid != null", 
     "$comment_id": { 
     "comment": { 
      ".validate": "newData.isString() && newData.val().length < 100" 
     } 
     } 
    } 
    } 
} 

這些規則將起作用。但我可能會更新數據結構以刪除comment節點,因爲它不會添加任何值。