gpt4 book ai didi

javascript - Firestore 更新数据未捕获( promise )FirebaseError : Missing or insufficient permissions

转载 作者:行者123 更新时间:2023-12-05 02:08:11 25 4
gpt4 key购买 nike

我正在尝试从云 Firestore 更新预先存在的信息。这是我的规则:

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {

//match logged in user doc in users collection
match /users/{userId} {
allow read, write, update: if request.auth.uid == userId;
allow create: if request.auth.uid != null;
}
}
}

所以我可以通过 userId 读取数据并且它在我的网站上读取正常,但是当我尝试更新它时,我收到以下错误消息

error.ts:166 Uncaught (in promise) FirebaseError: Missing or insufficient permissions.
at new hi (https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:51421)
at https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:316738
at br.<anonymous> (https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:315592)
at Jt (https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:15221)
at br.I.dispatchEvent (https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:16063)
at Nr.ua (https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:45312)
at nr.I.Fa (https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:43219)
at ze (https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:21453)
at qe (https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:20854)
at xe.I.Ja (https://www.gstatic.com/firebasejs/7.9.3/firebase-firestore.js:1:23264)

cloud firestore image

这是我更新账户信息的代码

const updateForm = document.querySelector('#update-form');
updateForm.addEventListener('submit', (e) => {
e.preventDefault();

auth.onAuthStateChanged(user => {
console.log(user.uid);
if(user) {
db.collection('user').doc(user.uid).set({

// email: updateForm['update-email'].value,
name: updateForm['update-name'].value,
// dob: updateForm['update-dob'].value,
// phone: updateForm['update-phone'].value

})
} else {
updateAccountInfo();
}
})
});

我花了 5 个小时试图找出为什么我收到错误消息但没有成功。请指出正确的方向。

最佳答案

您的代码使用的是集合名称“user”,但您的规则和数据库使用的是“users”的复数形式。它们需要完全匹配。

关于javascript - Firestore 更新数据未捕获( promise )FirebaseError : Missing or insufficient permissions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61132720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com