I'm making a web page, but when entering the same ID an error should come out, but I have not been able to do it.
 function save () {
    if (validate  = true) {
        console.log("exists!")
    }else {
        
    var imei = document.getElementById('imei').value;
    var marca = document.getElementById('marca').value;
    var referencia = document.getElementById('referencia').value;
    var precio = document.getElementById('precio').value;
    db.collection("phone").add({
        Imei: imei,
        Marca: marca,
        Referencia: referencia,
        Precio: precio
    })
        .then(function (docRef) {
            document.getElementById('imei').value = '';
            document.getElementById('marca').value = '';
            document.getElementById('referencia').value = '';
            document.getElementById('precio').value = '';
        })
        .catch(function (error) {
            window.alert("Error adding document: ", error);
        });
    }
}save();
function validate () {
    firebase.database().ref(`phone/${Imei}/imei`).once("value", snapshot => 
    { const imei = snapshot.val(); 
        if (imei){ 
            console.log("user exists!"); 
        } 
    }); 
}If you can tell me where I have the error, or the best solution I would really appreciate it
 
    