【发布时间】:2021-03-14 15:56:09
【问题描述】:
我正在构建一个联系表单,并了解一种快速的方法是将数据写入 Firestore,然后使用 trigger e-mail 扩展来触发电子邮件。
我已经设置了联系表单页面,并且正在将输入验证后的字段发送到 firestore:
let db = firebase.firestore();
db.collection("users").add({
name: getInputVal('name'),
email: getInputVal('email'),
phone: getInputVal('phone'),
message: getInputVal('message')
})
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
console.error("Error adding document: ", error);
});
我仅将 Firestore 用于消息(其他所有内容都保存在实时数据库中,我已经设法创建了足够的安全规则)。我的权限似乎有问题?
我想设置什么:
- 允许未经身份验证的用户写入 Firestore
messages集合 - 只允许管理员用户阅读/删除消息
- 在数据库级别设置验证,任何字段的长度都不会超过 200 个字符,并且只能使用字符串类型
我尝试遵循实时数据库中的逻辑,并具有以下规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /messages/{message}{
allow write: if true
allow read: if "request.auth.uid === 'my_user_id'"
}
}
}
但是,每次我尝试运行上面的代码时,我最终都会遇到错误FirebaseError: Missing or insufficient permissions.。
【问题讨论】:
标签: firebase google-cloud-firestore