In the following example updatedData.maxChips
is set to the number 50000 and updatedData.maxScore
should not be defined.
function updatePlayerConditions(player) {
let updatedData = request.resource.data;
let originalData = resource.data;
let condition1 = updatedData.maxChips > 0 ? updatedData.maxChips == originalData.maxChips : true; // worked
let condition2 = updatedData.maxScore ? updatedData.maxScore = originalData.maxScore : true;
return condition1 && condition2;
}
The above code for condition1 works, but when I change updatedData.maxChips > 0
to just updatedData.maxChips
or !!updated.data.maxChips
it doesn't work. If JS truthiness rules applied to firestore security rules than this doesn't make sense to me.
And I get the error FirebaseError: PERMISSION_DENIED: from condition2.
How can I use an undefined value in security rules? It would be especially helpful if someone could explain or point to how firebase firestore security rules work generally. I've already looked here: https://firebase.google.com/docs/rules/rules-language#building_conditions
Update: I realized I could replace updatedData.maxScore
at the start of the ternary with maxScore in updatedData
thanks to finding this question: Firestore Security Rules: request.time "undefined on object". I'd still be happy to find or read an explanation on how truthiness in firestore security rules works.