I'm building a contact form and understood that a quick way to do it would be to write the data into the firestore and then use the trigger e-mail extension to fire the email.
I've set up the contact form page already and are sending the fields after input validation to the firestore:
let db = firebase.firestore();
db.collection("users").add({
name: getInputVal('name'),
email: getInputVal('email'),
phone: getInputVal('phone'),
message: getInputVal('message')
})
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
console.error("Error adding document: ", error);
});
I'm using Firestore only for messages (and everything else is kept in the real-time database, where i've managed to create sufficient security rules). Looks like something is wrong with my permissions?
What i'd like to set-up:
- Allow non-authenticated users to write into Firestore
messagescollection - Allow only admin users to read/delete messages
- Set up a validation on db level that the length of any fields wouldn't exceed 200 characters and would only be with a type of String
I tried following the logic from real time database, and have the following rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /messages/{message}{
allow write: if true
allow read: if "request.auth.uid === 'my_user_id'"
}
}
}
However, I end up catching an error FirebaseError: Missing or insufficient permissions. every time I try to run the code above.