2017-09-13 68 views
1

這是我的規則:Firebase規則權限被拒絕,但爲什麼?

{ 
    "rules": { 
    "freecoinsrequest":{ 
     ".read": false, 
     ".write": " 
     newData.child('uid').val() == auth.uid 
     1. && (root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').val() < now - 10000 
     2. || !root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').exists()) 
     " , 
     "uid":{ 
     ".validate" : true 
     }, 
     "$other":{ 
      ".write": false, 
      ".validate": false 
     } 
    }, 
    } 
} 

所以用戶應該只能夠寫的路徑,如果:

  • JSON中包含了「UID」作爲重點,而他的uid的值在10秒前
  • 他沒有寫信給服務器/ lasttimetookfreecoins或
  • 他從來不寫信給服務器/ lasttimetookfreecoins

我不明白爲什麼它會在模擬器中被拒絕。從規則中可以看出,當我取消註釋1和2時,它會起作用。

謝謝。

回答

1

在我的測試中,規則在/users/$uid/server/lasttimetookfreecoins存在時產生了期望的結果,但在沒有時失敗。扭轉固定條件的順序:

newData.child('uid').val() == auth.uid 
    && (!root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').exists() 
    || root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').val() < now - 10000)