我有一个具有以下结构的收藏项目:
{
name
roles {
id_user1: 'owner',
id_user2: 'read'
}
}
现在,我希望“所有者”用户获得项目列表。我尝试设定规则:
service cloud.firestore {
match /databases/{database}/documents {
match /projects/{project} {
function isSignedIn() {
return request.auth != null;
}
function getRole(rsc) {
return rsc.data.roles[request.auth.uid];
}
function isOneOfRoles(rsc, array) {
return isSignedIn() && (getRole(rsc) in array);
}
// <-- 'Read' rules here -->
allow read: if isOneOfRoles(resource, ['owner', 'writer', 'commenter', 'reader']);
match /records/{record} {
allow create, read, write: if request.auth.uid != null
}
}
match /users/{userId}{
allow create
allow read: if request.auth.uid != null
allow write: if request.auth.uid == userId
}
match /notifications/{notification}{
allow read, write: if request.auth.uid != null
}
}
}
如果我使用“所有者”用户访问单个项目,则说明成功。 但是当我访问由该用户创建的项目列表时,没什么。
我的反应代码:
const mapStateToProps = (state) => {
debugger
return {
projects: state.firestore.ordered.projects,
auth: state.firebase.auth,
// notifications: state.firestore.ordered.notifications
}
}
export default compose(
connect(mapStateToProps),
firestoreConnect([
{ collection: 'projects', orderBy: ['createdAt', 'desc']},
// { collection: 'notifications', limit: 8, orderBy: ['time', 'desc']}
])
)(Dashboard)
当我调试并检查state
时,我看到了:
state: {
auth: {authError: null}
...other...
}
如何使用Firestore规则按用户查询项目列表?