我试图将安全规则建立在对另一个对象的引用上.
我有一组用户和角色集合.用户对象具有名为"role"的字段,该字段是对roles集合中特定文档的引用.
users
id
name
role <-- reference to particular role
roles
id
name
isSuperUser
Run Code Online (Sandbox Code Playgroud)
这里的目标是允许具有特定角色的用户(isSuperUser == true的角色)编辑任何其他角色或其子集合;
以下是我原本认为可行的规则:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId=**} {
allow read, write: if request.auth.uid == userId;
}
match /roles/{roleId=**} {
function isSuperUser() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role.isSuperuser == true;
}
allow read: if request.auth.uid != null;
allow write: if isSuperUser();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经确认了以下作品,但它并没有那么有用......
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role != null;
Run Code Online (Sandbox Code Playgroud)
如果有更好的方法来完成角色基础安全,我很满意.
缺乏任何调试工具使这非常令人沮丧.
我不确定这个问题的真正原因是什么。我认为它是 Typescript,但它可能是 ng-packagr 或 Angular。它仅在我更新到 Angular 9 时才开始。
这是我在生产构建中收到的消息...
WARNING: Conflicting namespaces: dist/web-apps-shared/esm2015/public_api.js re-exports '?0' from both dist/web-apps-shared/esm2015/lib/api-applications/reducers.js and dist/web-apps-shared/esm2015/lib/account-codes/reducers.js (will be ignored)
Run Code Online (Sandbox Code Playgroud)
这是导致这种情况的来源之一......
export const selectTotalAccountCodes = createSelector(selectSharedAccountCodeState,
(state: SharedAccountCodeState) => state.totalItems);
Run Code Online (Sandbox Code Playgroud)
编译器出于某种原因接受函数参数并将其分配给 aconst然后像这样导出它......
const ?0 = (state) => state.totalItems;
export const selectTotalAccountCodes = createSelector(selectSharedAccountCodeState, ?0);
export { ?0 };
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么?0需要导出?它仅在此文件内部使用。我错过了什么吗?应该担心这个吗?在使用使用此代码构建的库时,它似乎不会引起问题。