Home > front end >  Flutter & Firestore: What way to get data with safety when the Firestore can't get a specific f
Flutter & Firestore: What way to get data with safety when the Firestore can't get a specific f

Time:10-11

The firestore can't get data with specific fields (ref).

I am using firestore in the flutter. It will not safety when I fetch all fields of a collection in the client app. The user can read some fields that the user shouldn't read.

Why firebase doesn't generate this function?

What I should do?

How do most people solve this problem?

Should I generate a sub-collection with only one document that is secret fields?

Should I generate a new collection containing the document id field that is the document id of a secret document that contains secret fields?

Or anything else, I am new to NoSQL and Firebase. Please, suggest me. Thank you.

CodePudding user response:

The two most common options are indeed to:

  1. Have a single top-level collection with the public information and then a subcollection under the user document with its secret/non-public information, typically indeed with a single document.
  2. Have two top-level collections, one with the public information and one with the secret/non-public information for all users.

In both cases you can then secure access to the documents with security rules.

  • Related