Val
Val

Reputation: 97

View only certain collections by user on Firebase/Firestore

How can make in Firebase/Firestore that every user must sees only his collection. I think to works by having the user_id in the name of the collection but it's a safe method? The same thing for Storage. I don't find any mechanism offered by Google.

Thank you

Upvotes: 0

Views: 352

Answers (1)

Clément
Clément

Reputation: 83

You can use a security rules like this

`service cloud.firestore {
  match /databases/{database}/documents {
    // Make sure the uid of the requesting user matches name of the user
    // document. The wildcard expression {userId} makes the userId variable
    // available in rules.
    match /users/{userId} {
      allow read, update, delete: if request.auth.uid == userId;
      allow create: if request.auth.uid != null;
    }
  }
}`

You can find more informations at this link

https://firebase.google.com/docs/firestore/security/rules-conditions

Upvotes: 2

Related Questions