I am trying to update pre-existing information from the cloud firestore. Here is my rules:
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;
}
}
}
so I can read the data by userId and it reads fine on my website, but when I try to update it, I get the following error message
error.ts:166 Uncaught (in promise) FirebaseError: Missing or insufficient permissions.
at new hi (.9.3/firebase-firestore.js:1:51421)
at .9.3/firebase-firestore.js:1:316738
at br.<anonymous> (.9.3/firebase-firestore.js:1:315592)
at Jt (.9.3/firebase-firestore.js:1:15221)
at br.I.dispatchEvent (.9.3/firebase-firestore.js:1:16063)
at Nr.ua (.9.3/firebase-firestore.js:1:45312)
at nr.I.Fa (.9.3/firebase-firestore.js:1:43219)
at ze (.9.3/firebase-firestore.js:1:21453)
at qe (.9.3/firebase-firestore.js:1:20854)
at xe.I.Ja (.9.3/firebase-firestore.js:1:23264)
cloud firestore image
Here is my code to update the account info
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();
}
})
});
I have spent 5 hours trying to figure out why I get the error message but had no luck. Please point me to the right direction.
I am trying to update pre-existing information from the cloud firestore. Here is my rules:
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;
}
}
}
so I can read the data by userId and it reads fine on my website, but when I try to update it, I get the following error message
error.ts:166 Uncaught (in promise) FirebaseError: Missing or insufficient permissions.
at new hi (https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:51421)
at https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:316738
at br.<anonymous> (https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:315592)
at Jt (https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:15221)
at br.I.dispatchEvent (https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:16063)
at Nr.ua (https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:45312)
at nr.I.Fa (https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:43219)
at ze (https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:21453)
at qe (https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:20854)
at xe.I.Ja (https://www.gstatic./firebasejs/7.9.3/firebase-firestore.js:1:23264)
cloud firestore image
Here is my code to update the account info
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();
}
})
});
I have spent 5 hours trying to figure out why I get the error message but had no luck. Please point me to the right direction.
Share Improve this question edited Apr 10, 2020 at 1:32 Tucker Powers asked Apr 10, 2020 at 1:26 Tucker PowersTucker Powers 311 silver badge3 bronze badges2 Answers
Reset to default 6Your code is using the collection name "user", but your rules and database are using "users" plural. They need to match exactly.
You did a minor spelling mistake like I had done, always write correct spellings of the db collections. In your case it should be "users" instead of "user" in the code.
db.collection('users').doc(user.uid).set