2016-05-17 71 views
1

我的火力點的數據是這樣的,在我的web應用大家誰訪問它就會通過火力匿名身份驗證,他們的UID存儲與每一個崗位的用戶創建:Firebase安全性和規則,我如何讓用戶刪除自己的數據?

"-KF5N2V_dKD1dMHebUqc" : { 
    "note" : "Hello everybody", 
    "pos" : { 
     "lat" : 40.3628851, 
     "lng" : -74.0493175 
    }, 
    "time" : 1460395853884, 
    "uid" : "f8cf7863-5607-4e2b-97d7-6a121261466c" 
    }, 
    "-KHwyP-tnWNOA3nxzEm4" : { 
    "note" : "hi", 
    "pos" : { 
     "lat" : 37.0947156, 
     "lng" : -121.0179501 
    }, 
    "time" : 1463459362615, 
    "uid" : "f8cf7863-5607-4e2b-97d7-6a121261466c" 
    } 

我希望我的火力規則設置,以便只有匿名用戶可以通過自己的帖子刪除他們。

到目前爲止,我只能夠想出這個閱讀火力文檔後:

{ 
    "rules": { 
     ".read": "auth != null", 
     ".write": "auth != null", 
     "$msg": { 
     ".validate": "newData.hasChildren(['note','time','uid','pos']) 
      && newData.child('note').isString() && newData.child('time').isNumber() 
      && newData.child('uid').isString() && newData.child('note').isString() 
      && newData.child('pos/lat').isNumber() && newData.child('pos/lng').isNumber()" 
     } 
    } 
} 

回答

4

你需要向下移動.write許可,並把它綁數據:

{ 
    "rules": { 
     ".read": "auth != null", 
     "$msg": { 
     ".write": "!data.exists() || (!newData.exists() && data.child('uid').val() === auth.uid)" 
     ".validate": "..." 
     } 
    } 
} 

這是一個有點從火力地堡文件的這兩個部分混合和匹配:

+0

注:如果你想模仿,如果這個工程,確保你的位置包括$味精變量結尾,如'/ msg'。我一直在獲取權限,拒絕嘗試寫入根目錄/ {「some-msg」:「bar」 } – Voy