javascript - 用户如何在 vue.js 上使用 firestore 读取/写入自己的数据?
问题描述
我的目标是让用户只读取和写入自己提交的数据。
提交数据时,我可以获取它,但它目前可供所有用户查看。
在 Firestore 上使用新的安全规则:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, update, delete: if request.auth.uid == userId;
allow create: if request.auth.uid != null;
}
}
}
Uncaught Error in onSnapshot: FirebaseError: Missing or insufficient permissions.
即使我的集合被命名users
并且我的文档 id 是用户 uid,我也可以在 chrome 上进入控制台。
在这里,我使用插值和 v-for 来显示数据: <sidebar-link id="user.uid" :to="
/${user.title} " :name="
${user.title}" icon="tim-icons icon-atom" v-for="(user) in users" :key="user.title"/>
在这里,我正在尝试从 firestore 获取数据:
created () {
db.collection('users').onSnapshot(res => {
const changes = res.docChanges()
changes.forEach(change => {
if (change.type === 'added') {
this.users.push({
...change.doc.data(),
id: change.doc.id
})
}
})
})
}
添加 if 语句read, update and delete
显然可以让我再次看到数据,但它也允许所有用户看到它,这不是我想要的安全性。
解决方案
推荐阅读
- r - 如何更改 ggplot 中 geom_text 的字体?
- django - 如何在 django 测试期间只创建相关的模型字段?
- postgresql - Postgresql序列增量自动随机值
- git - GIT - 合并冲突后如何从提交中删除文件?
- c# - 遍历 XML 中的所有节点
- linux - bash 不理解 .vimrc 的语法
- html - 如何防止 div 的位置在调整屏幕大小时发生变化
- javascript - Vue FontAwesome 图标在计算上不会改变
- nginx - 如何在 nginx 中将 ip 重定向到 https 域
- javascript - 使用可恢复的上传 url 在 React js 中上传文件在谷歌云存储中失败,引发 CORS 策略错误