【发布时间】:2020-07-18 18:58:43
【问题描述】:
问题: 当我使用firestore请求模拟器时,它可以按我的意愿工作,但是当我通过我的应用程序对其进行测试时,即使我没有经过身份验证,它也可以让我发出创建请求。 请注意,我正在使用 react、easy peasy 状态管理和 firebase spark 计划。
代码:
-
规则
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow write: if request.auth != null; allow read; } } }
提交到数据库:
componentDidMount() {
try {
this._db = firebase.firestore();
this._db
.collection("txts")
.limit(50)
.orderBy("timeMade", "asc")
.onSnapshot((querySnapshot) => {
this.setState({ messages: [] });
querySnapshot.forEach((doc) => {
this.setState({
messages: [...this.state.messages, doc.data().txt],
});
});
});
} catch (err) {
alert("Must sign in first!");
}
}
uploadData = (e) => {
e.preventDefault();
if (this.state.m.trim()) {
this._db.collection("txts").add({
txt: this.state.m,
timeMade: Date.now(),
});
this.setState({ m: "" });
}
};
我尝试过的事情:
- 我已经等了 1 分钟(据说最多等 1 分钟)
- 从中型帖子中复制粘贴的规则,符合我的要求(仍然无效)
【问题讨论】:
-
安全规则本身没有任何作用。请编辑您的问题以包含您在应用程序中使用但不起作用的代码。另请参阅:how to create a minimal, complete, verifiable example。
-
@FrankvanPuffelen 更改了它,请您现在帮帮我
标签: javascript firebase google-cloud-firestore firebase-authentication firebase-security