Firestore rule schema for an object

I have a collection. Each document has object readers that will store the uid of the people who will have access to the documents. This can be one or more users who can access the document. enter image description here

I am using angular firebase

constructor(private afAuth: AngularFireAuth, private afs: AngularFirestore) { this.afAuth.authState.subscribe(auth => { this.users = afs.collection<User>('users', ref => ref.where('readers.' + auth.uid, '==', true)).valueChanges(); }); } 

If I use a rule that allows everything to be read, the correct entries will be displayed on my page

 match /users/{userId=**} { allow read, write; } 

If I add a rule for filtering using uid, I get the Missing or insufficient permissions error.

 match /users/{userId=**} { allow read, write: if resource.data.readers[request.auth.uid] == true || resource.readers[request.auth.uid] == true; } 

Appreciate any help regarding what I did wrong for the rules. Thanks in advance.

+5
source share
2 answers

Have you tried changing your rules in the database rules to auth = null?

 { "rules": { ".read": "auth == null", ".write": "auth == null" } } 
0
source
 //Object structure "documentToShare"{ documentData: {}, documentUsers:{user1UID,user2UID} } //Firebase rules Rules:{ "documentToshare: { match documentToshare/documentUsers/&uid } } 

this is a quick example and probably not valid, but it should give you an idea

0
source

Source: https://habr.com/ru/post/1272825/


All Articles