【发布时间】:2020-03-17 23:12:56
【问题描述】:
我正试图弄清楚如何从我的云存储中读取数据。
我有一条数据库规则说:
// Demo projects
match /project/{projectId} {
allow read;
allow write;
}
然后,我尝试使用react firestore hooks 来读取数据。
我有
import { useDocument } from 'react-firebase-hooks/firestore';
import { fsDB, firebase, settings } from "../../../../../firebase";
const Overview = props => {
const { state } = useStateMachine(updateAction);
const [value, loading, error] = useDocument(
firebase.firestore().doc('hooks/kN7ZOK5HRmDs5KhKTYSb'),
{
snapshotListenOptions: { includeMetadataChanges: true },
}
);
return (
<div>
<Paragraph>
<h2 style={{color: '#213159'}}>
<p>
{error && <strong>Error: {JSON.stringify(error)}</strong>}
{loading && <span>Document: Loading...</span>}
{value && <span>Document: {JSON.stringify(value.data())}</span>}
</p>
这似乎有效,因为生成了一条错误消息:
错误:{"code":"permission-denied","name":"FirebaseError"}
我的项目表已将所有读取和写入权限设置为 true(而我正在弄清楚如何使其工作)。
谁能看到从 Cloud Firestore 读取数据还需要什么?
【问题讨论】:
-
我不能 100% 确定,但您可能需要将这些规则更改为
allow read: if true; allow write: if true。 -
文档不需要 if 语句。另外,我已经能够使用我设置的方法写入数据库,所以 if 语句似乎没有必要
标签: reactjs firebase google-cloud-firestore react-hooks