Reputation: 3690
Although the user already logged in, that user can only fetch on data out from Firestore. And that data is his own data. Why is that? How do I get every data from Firestore then?
Firebase Rule
//A user can only read/write their own information
match /users/{userId} {
allow read, write: if request.auth.uid == userId;
}
Permission Denied Console
W/Firestore(32060): (21.3.0) [Firestore]: Listen for Query(users order by __name__) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
I/System.out(32060): com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.
Firebase Code
// All User Stream
List<AllUser> _userList(QuerySnapshot snapshot) {
//print('in userList');
return snapshot.documents.map((doc) {
//print('name : ${doc.data['name']}');
return AllUser(
name: doc.data['name'] ?? null,
email: doc.data['email'] ?? null,
uid: doc.data['uid'] ?? null,
signInMethod: doc.data['signInMethod'] ?? null,
locale: doc.data['locale'] ?? null,
score: '20000',
);
}).toList();
}
Stream<List<AllUser>> get allUserData {
//print('in allUserData');
return userCollection.snapshots().map(_userList);
}
Please have a look at my code. And I am looking forward to hearing from all of you. Thank you so much.
Upvotes: 0
Views: 215
Reputation: 2477
your Firestore rule as explained can only allow user to modify documents if they own these documents. if you want to allow any user to read and write to the database then change to:
match /users/{userId} {
allow read, write: if request.auth.uid != null;
}
be aware that this will open your database to the public and any authenticated user can read and write. let me know if this is what you want.
Upvotes: 1