Firestore Security Rules allow specific field only [duplicate]

為{幸葍}努か 提交于 2021-01-20 11:27:33

问题


I am trying to implement security rule to limit users to access only specific fields inside a document. My data structure goes like this:

document {
  name: John,
  dob: 1994,
  email: john@hotmail.com
}

I want to limit the name field to read, write by owner; dob field to read by owner, create by owner; email to read by owner, update by owner

I read the documentation, and it seems that I can only control access of a specific document with security rules. It didn't mention anything to allow access to a specific field. What I should do in order to allow access to specific fields inside a document?


回答1:


Security rules can't be used to limit access to individual fields in a document. If a user has direct read access to a document, they can always read every field in the document.

Your only alternatives here are:

  1. Split the restricted fields into a document in another collection, and protect that collection differently.
  2. Reject direct access to the collection entirely, and force users through an API endpoint that strips out the restricted fields based on the user's identity, which was passed to the endpoint.


来源:https://stackoverflow.com/questions/62904085/firestore-security-rules-allow-specific-field-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!