android - firestore:让用户更新,只删除自己的数据
问题描述
这些是我当前的安全规则:
service cloud.firestore {
match /databases/{database}/documents {
match /tournaments/{tournament=**} {
allow update, delete: if request.auth.uid == resource.data.author;
allow create: if request.auth.uid != null;
allow read: if true;
}
}
}
一切正常,由于“缺少或权限不足”,只有更新或删除不起作用
这是我的代码
mDocRef
.update(key, score)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "DocumentSnapshot successfully updated!");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Error updating document", e);
}
});
mDocRef 引用路径为“tournaments/tournamentID/aColletion/aDocument”的文档
以下是创建 mDocRef 的代码:
mTournamentDocRef = mTournamentColRef.document();
mDocRef = mTournamentDocRef.collection("aCollection").document();
需要注意的一些事项:
- 用户在整个过程中通过firebase登录
- 我尝试使用 .where("author", "==", user.uid) 但出现“无法解析方法”错误
谢谢您的帮助!
解决方案
我检查了文档,这些是您正在寻找的规则:
match /users/{userId} {
allow read, update, delete: if request.auth.uid == userId;
allow create: if request.auth.uid != null;
}
以及作为参考的文档链接:https ://firebase.google.com/docs/firestore/security/rules-conditions?authuser=0
推荐阅读
- java - @EnableBatchProcessing 处不满足的依赖异常
- mysql - MySQL表中的createdAt字段是否可编辑?
- javascript - 使用 JSON.parse 重命名 JSON 字段
- python - logging.debug() 正在打印与常规 print() 不同的内容
- c# - 使用 TextBox 控件将 MapBasic 与 .NET 问题集成
- javascript - 无法并排显示选择字段?
- reactjs - GoogleMap ReactJS:如何将状态值传递到 googlemap 的默认中心
- google-sheets - 谷歌表数据验证问题
- rest - 从基本 Spring Boot Camel REST DSL 请求中获取 404“未找到”错误
- microservices - 如何监控本地网络中的连接