Firebase rules for increment operation not working -
i have simple firebase database, single entry "async-testing/companies: 0".
i have following firebase rules, meant set "companies"
0 if undefined, , otherwise allow write if greater current value of "companies"
1:
{ "rules": { ".read": "auth != null", ".write": "auth != null", "async-testing": { "companies": { ".validate": "(data.exists() && (newdata.val() === data.val() + 1)) || (!data.exists() && newdata.val() == 0)" } } } }
however, when attempt set "companies" equal 1 in firebase simulator, not work:
even stranger, when set firebase rules accept write if "companies"
undefined, works correctly:
{ "rules": { ".read": "auth != null", ".write": "auth != null", "async-testing": { "companies": { ".validate": "!data.exists()" } } } }
any appreciated. thanks.
the 'async-testing' layer not required. try:
{ "rules": { ".read": "auth != null", ".write": "auth != null", "companies": { ".validate": "(data.exists() && (newdata.val() === data.val() + 1)) || (!data.exists() && newdata.val() == 0)" } } }
Comments
Post a Comment