title: Firebase database, make auth uid the default id of a document
body: <p>How can I make the generated <code>uid</code> from <code>auth</code>'s <code>createUserWithEmailAndPassword(email, pass)</code> be the <code>uid</code> of document? </p>
  
  <p>I have this code as a signup function : </p>
  
  <pre><code>$scope.signup = function (user) {
      auth.createUserWithEmailAndPassword(user.email, user.password)
          .then(ok =&gt; {
              // remove pass before saving
              delete user.password; 
              // assigning the uid
              user.uid = ok.uid;
              // saving to userRef = ...ref().child('/accounts')
              userRef.push(user)
                  .then(snap =&gt; console.log(snap))
                  .catch(err =&gt; console.log(err));
          })
          .catch(e =&gt; console.log(e.message));
  }
  </code></pre>
  
  <p>The code above does what is expected, the output is here </p>
  
  <p><a href="https://i.stack.imgur.com/h4TgD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h4TgD.png" alt="enter image description here"></a></p>
  
  <p>So data was saved successfully but I want the value of this <code>-KOQOXUGH9Ahh9fukVkg</code> to be the value of the <code>uid</code> which is <code>pFNhADogjkZFz7E4osXPY48wJdS2</code>. </p>
  
  <p>It seems that the <code>-KOQOXUGH9Ahh9fukVkg</code> is being added by <code>firebase</code> automatically. How do I control that? </p>
  
  <p>Here's my <code>rules</code> </p>
  
  <pre><code>{
    "rules": {
      ".read": "auth != null",
      ".write": "auth != null",
          "accounts": {
        ".write": "auth != null",
        ".read": "auth != null",
        "$uid": {
          ".write": "$uid === auth.uid",
          ".read": "$uid === auth.uid"
        }
      }
    }
  }
  </code></pre>