0
我剛剛使用Firebase規則,但我已閱讀文檔。我知道最上面的規則優先,但仍然應該運行驗證規則。我的問題是我試圖創建唯一的用戶名,但每當我模擬插入驗證從未運行。我想要創建的驗證規則應該檢查用戶名集合,看看它是否已經存在,如果確實存在,那麼寫入失敗。 我已經發布了我的數據結構和規則。該fire_uid
是火災基地產生的UID的佔位符Firebase驗證規則不起作用
當前數據庫
{
"userProfile" : {
"fire_uid" : {
"email" : "[email protected]",
"name" : "matt maxton"
},
"fire_uid" : {
"email" : "[email protected]",
"name" : "victor tictor"
}
},
"usernames" : {
"testcaseusername" : "fire_uid"
}
}
火力地堡規則
{
"rules": {
"$uid": {
".write": "auth !== null",
".read": "auth !== null && auth.provider === 'password'",
"usernames": {
".validate": "!root.child('usernames').child(newData.val()).exists() ||root.child('usernames').child(newData.val()).val() == $uid "
}
}
}
}
模擬測試(我確信,在本次測試中的用戶ID是不同用於在數據庫中創建條目的uid
位置:/用戶名
JSON數據:{ 「testcaseusername」: 「fire_uid」}
的「用戶名」元素是對數據庫的根,它在同級別的層次結構中的 – VirtualProdigy
我想你可能已經指出了我在「用戶配置文件」正確的方向,驗證規則只檢查$ uid /用戶名,我需要檢查/用戶名 – VirtualProdigy