【发布时间】:2021-10-13 01:30:36
【问题描述】:
我是 firebase / firestore 的新手,我正在尝试在登录和验证用户时、在客户端和使用 React 时创建一个新集合。 我在这里阅读了其他几篇文章,并将读取和写入的数据库规则设置为 true,但是,我一直在 Firestore 数据库上收到错误,而如果我初始化实时数据库,它可以完美运行。 另外,我可以获取和读取数据,但不能写入。
我的代码很简单:
export default function Login() {
const [isAuthenticated, setAuthenticate] = useState(false);
const [newEditor, setNewEditor] = useState("");
const uiConfig = {
signInFlow: "popup",
signInOptions: [firebase.auth.GoogleAuthProvider.PROVIDER_ID],
callbacks: {
signInSuccessWithAuthResult: (user) => {
console.log("success");
createUserRoles(newEditor);
},
},
};
useEffect(() => {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
if (user.email.split("@")[1] === "something.com") {
setAuthenticate(!!user);
setNewEditor(user.email);
console.log(newEditor);
} else {
console.log("not allowed");
}
}
});
});
const createUserRoles = (user) => {
//on login the user will be added to editors collection with default value of reviewer
console.log("hello from createeee");
const editorsRef = firebase.database().ref("editors");
const editor = {
email: "user.email",
role: "reviewer",
lastSession: Date.now(),
};
editorsRef.push(editor);
};
return (
.....
我的规则是这样设置的:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if true;
allow write: if true;
}
}
}
有人知道我该怎么做吗?
【问题讨论】:
标签: javascript reactjs firebase google-cloud-firestore firebase-security