Firestore security rules: How to validate that a field is undefined?

前端 未结 2 898
迷失自我
迷失自我 2020-12-18 06:40

When a user signs up and they initialise their data in firestore, I want to validate that they aren\'t attempting to set their role (i.e. so they\'re not setting it to \'adm

相关标签:
2条回答
  • 2020-12-18 06:57

    Use the in operator to find out if a property of an object doesn't exist.

    !("role" in request.resource.data)
    

    This yields a boolean. See it in the rules API docs for the Map type.

    0 讨论(0)
  • 2020-12-18 07:10

    Try with writeFields if other solutions do not work.

    !("role" in request.writeFields)
    
    0 讨论(0)
提交回复
热议问题