Completely new to firebase, I want to set a phone number as the primary key (uid) and email as the secondary key. How can I prevent duplication of these two if they exist in my firebase database? I don't have any authentication in my application. I'm doing this for a contact form to prevent duplication
Below is my JS code
// Submit form
function submitForm(e){
e.preventDefault();
// Get values
var name = getInputVal('name');
var company = getInputVal('company');
var email = getInputVal('email');
var phone = getInputVal('phone');
var message = getInputVal('message');
// Save message
saveMessage(name, company, email, phone, message);
}
// Function to get get form values
function getInputVal(id){
return document.getElementById(id).value;
}
// Save message to firebase
function saveMessage(name, company, email, phone, message){
var newMessageRef = messagesRef.push();
newMessageRef.set({
name: name,
company:company,
email:email,
phone:phone,
message:message
});
}
And below is the rule which I have set in firebase
{
"rules": {
".read": "false",
".write": true,
"phone": { // assuming this as primary key
".validate": "newData.isString() &&
newData.val().length == 10 &&
!root.child('phone').child(newData.val()).exists()"
}
}
}