Problems in adding data to the database
<p>My problem is to add data to the database by taking the information from a form.
I want to add the information as "name". I can add "email" correctly but not other data.</p>

<p>My code:</p>

<pre class="lang-js prettyprint-override"><code>buttonsignup.addEventListener('click', error =&gt; {
  var nameCompany = document.getElementById('nameCompany').value;
  var email = document.getElementById('email').value;
});

function add(nameCompany,email) {
    firebase.database().ref().child('users_company').push({
        nameCompany: nameCompany,
        email: email
    });
}


function intFirebase () {

    /*CURRENT USER*/
    firebase.auth().onAuthStateChanged(function(user) {
        if (user != null) {
            console.log(user);
            console.log('El UID es '+user.uid);
            add(nameCompany,user.email);
        } else {
            console.log('No user is signed in.');
        }
    });
}

window.onload = function() {
    intFirebase();
}
</code></pre>

<p>Okay, After turning the coffee into code. I found this solution. But ... Is it a good practice?</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const database = firebase.database();
var user = firebase.auth().currentUser;

/* BOTON SIGNUP */

buttonsignup.addEventListener('click', error =&gt; {

 var nameCompany = document.getElementById('nameCompany').value;
 var email = document.getElementById('email').value;
 var password_1 = document.getElementById('password_1').value;
 var password_2 = document.getElementById('password_2').value;
 
 if (password_1 == password_2) {
  if (password_1.length &lt; 8) {
   console.log('Contraseña muy corta');
   document.getElementById("errorPassword").innerHTML = "8 characters";
  } else {
   firebase.auth().createUserWithEmailAndPassword(email, password_1).then (function(result) {
    add(nameCompany,email);
   }).catch(function (error) {
    var errorCode = error.code;
    var errorMessage = error.message;
    };
   });
  }
 } else{
  console.log('errorPassword');
 }
});

function add(nameCompany,email) {
 firebase.database().ref().child('users_company').push({
  nameCompany: nameCompany,
  emailCompany: email
 });
}


function intFirebase () {

 /*CURRENT USER*/
 firebase.auth().onAuthStateChanged(function(user) {
  if (user != null) {
   console.log(user);
   console.log('El UID es '+user.uid);
  } else {
   console.log('No user is signed in.');
  }
 });
}

window.onload = function() {
 intFirebase();
}</code></pre>
</div>
</div>
</p>

<p>And database rules</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>{
  "rules": {
    "users_company": {
      "$uid": {
        ".read": "auth != null &amp;&amp; auth.uid === $uid",
        ".write": true,
          //Change this code to: I can not do scripts in the database. -&gt; ".write": "auth != null &amp;&amp; auth.uid === $uid",
        "nameCompany" : {
         ".validate": "newData.isString() &amp;&amp; newData.val().length &lt; 100"
        },
        "emailCompany" :{
         ".validate": "newData.isString() &amp;&amp; newData.val().length &lt; 100"
        }
      }
    }
  }
}</code></pre>
</div>
</div>
</p>