I have a problem of understanding with the security rules of cloud firestore. I don't understand how to check a user's uid with a map where they can access their data.
Thank you in advance for your answers
Here is the rules i have tried
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
//TEST ONLY
//match /{document=**} {
// allow read, write;
//}
// match logged in user doc in users collection
match /users/users/{userId} {
allow create : if request.auth.uid != null;
allow read : if request.auth.uid == userId;
match /{anything=**} {
allow read, write : if request.auth.uid == userId;
}
}
}
}
And here an exemple of how i use Firestore :
// Collection reference
final CollectionReference _usersCollection = Firestore.instance.collection('users');
Stream<List<double>> get existingRecord {
return _usersCollection.document('users').snapshots()
.map(_existingRecordListFormSnapshot);
}
List<double> _existingRecordListFormSnapshot(DocumentSnapshot snapshot) {
...
double tips = snapshot.data['$uid']['data']['$year']['$month']['$week']['$day']['Tips'];
}
My problem is that I want only the user to have access to their data. For this I made a 'users' document which contains a 'users' map which contains all user data, named with their unique uid. And I am unable to set up the security rules so that only the user has access to his data.
The diagram looks like this: users / users / [{userID}, {userID}, ...]
I don't know if I'm clear but I really can't find how to only allow the user to access their data in the users data map