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

前端 未结 2 899
迷失自我
迷失自我 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.

提交回复
热议问题