Currently, I have a user who is logged in with a Google account, and their user id in Firebase is '123'.
In Firestore data, there is a collection named 'users' with a single document labeled '123' containing the field 'name: "test"'
The Firestore rules are set as follows:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, update, write, delete: if request.auth.uid == userId;
}
}
}
In my component, the code snippet looks like this:
users: Observable<User[]>;
ngOnInit()
{
this.users = this.firestore.collection<User>('users');
}
constructor(public auth: AngularFireAuth, private firestore : AngularFirestore) {}
HTML:
<ul>
<li *ngFor='user of angObs | async>
{{ user.name }}
<li>
<ul>
<div *ngIf='auth.user | async as user'>
<p>User id:</p>
{{ user.uid }}
</div>
The HTML displays:
User id:
123
When the rule is request.auth.uid != null;
, the user can see the data.
On the other hand, when the rule is request.auth.uid == userId;
, the user cannot view the data.
What could be going wrong here?