Firestore规则:为什么调用者没有执行指定操作的权限?
Firestore rules: why the caller does not have permission to execute the specified operation?
我有一个包含具有以下字段的文档的集合
- uid:创建文档的用户的用户ID
- anotherId: 是另一个id
- andAnotherId: 是另一个id
- date: 创建日期秒加1,000,000秒
在 flutter 中我有以下查询
_firestore
.collection('subscriptions')
.where('anotherId', isEqualTo: '1')
.where('andAnotherId', isEqualTo: '2')
.where('date', isGreaterThanOrEqualTo: dateInSeconds)
.limit(1)
.get()
.then(....
我想设置一个规则,只有创建该文档的用户才能阅读该文档。我写了以下内容,但它不起作用。有谁知道为什么吗??
match /subscriptions/{item} {
allow read: if request.auth != null
&& request.auth.uid == resource.data.uid;
}
请注意,如果我编写此规则,它会起作用(但我想避免其他用户可以读取其他用户创建的文档)
match /subscriptions/{item} {
allow read: if request.auth != null;
}
我已经通过如下更改查询解决了问题,但我仍然不明白为什么它之前不起作用
_firestore
.collection('subscriptions')
.where('uid', isEqualTo: uid)
.where('anotherId', isEqualTo: '1')
.where('andAnotherId', isEqualTo: '2')
.where('date', isGreaterThanOrEqualTo: dateInSeconds)
.limit(1)
.get()
.then(....
我有一个包含具有以下字段的文档的集合
- uid:创建文档的用户的用户ID
- anotherId: 是另一个id
- andAnotherId: 是另一个id
- date: 创建日期秒加1,000,000秒
在 flutter 中我有以下查询
_firestore
.collection('subscriptions')
.where('anotherId', isEqualTo: '1')
.where('andAnotherId', isEqualTo: '2')
.where('date', isGreaterThanOrEqualTo: dateInSeconds)
.limit(1)
.get()
.then(....
我想设置一个规则,只有创建该文档的用户才能阅读该文档。我写了以下内容,但它不起作用。有谁知道为什么吗??
match /subscriptions/{item} {
allow read: if request.auth != null
&& request.auth.uid == resource.data.uid;
}
请注意,如果我编写此规则,它会起作用(但我想避免其他用户可以读取其他用户创建的文档)
match /subscriptions/{item} {
allow read: if request.auth != null;
}
我已经通过如下更改查询解决了问题,但我仍然不明白为什么它之前不起作用
_firestore
.collection('subscriptions')
.where('uid', isEqualTo: uid)
.where('anotherId', isEqualTo: '1')
.where('andAnotherId', isEqualTo: '2')
.where('date', isGreaterThanOrEqualTo: dateInSeconds)
.limit(1)
.get()
.then(....