Firestore security rules denying access.
Rules are:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{id} {
allow create, update, delete: if request.auth != null && request.auth.uid == id;
allow read: if request.auth != null;
}
}
}
playground rules indicate '...==...'
and '&&' as false. What is wrong with this? Help appreciated very much!
Full rules and screenshot:
allow create, update, delete: if request.auth != null && request.auth.uid == id;
From your screenshot, you are running an update simulation.
request.auth != null
will fail if user is not logged in.request.auth.uid == id
will fail if uid != id;From your screenshot, we can see that authenticated is set to true. Therefore condition 1 will pass.
It is presently failing because of the 2nd condition. request.auth.uid == id
Presently, the id == 'user', but request.auth.uid != 'user';
Solution. Set your request.auth.uid to 'user'. To do that, go under authenticated, under firebase UID, put 'user' (as your firebase uid). It should work.
NB: it is possible that you are not struturing your data properly. Your present data structure is something like 'users/user', instead it should be 'users/{userId}' where userId is generated by firebase when user creates account.