title: Firebase rules (permission denied)
body: <p>I am trying to make a project in Firebase for practice. Here is what i am doing. I am using Email Authentication and when a person signs up with email and password, my app gets his name and add to the Firebase database with his user id. 
  Here is the database in Firebase i set</p>
  
  <pre><code>{
  "rules": {
  "users": {
  
    "$uid": {
        ".read": "auth != null &amp;&amp; auth.uid == $uid",
        ".write": "auth != null &amp;&amp; auth.uid == $uid",
      "items": {
  
        "$item_id": {
          "title": {
            ".validate": "newData.isString() &amp;&amp; newData.val().length &gt; 0"
          }
        }
      },
        "user-details":{
          "name" : {
            ".validate" : "newData.isString() &amp;&amp; newData.val().length &gt;= 0"
          }
        }
    }
  },
  
  "all-public" : {
    ".read" : "true",
      ".write" : "true"
  }
    }
  }
  </code></pre>
  
  <p>And here is the code in swift i wrote.</p>
  
  <pre><code>var dbref = FIRDatabase.database().reference()
              dbref.child("users").child("\(user?.uid)").child("user-details").child("name").setValue(name)
  
              dbref.child("all-public").child((user!.uid)).setValue(name)
  </code></pre>
  
  <p>The data to the second child <strong>all-public</strong> is added successfully but it fails to add the above first child and says permission denied.
  Here is what it says in the console.</p>
  
  <pre><code>2017-04-09 20:00:02.145 ToDo App[1573] &lt;Warning&gt; [Firebase/Database][I-RDB03812] setValue: or removeValue: at /users/Optional("klvexHq3GOQ4IiWpOs4WP7H4pmy1")/user-details/name failed: permission_denied
  2017-04-09 20:00:28.426 ToDo App[1573] &lt;Warning&gt; [Firebase/Database][I-RDB03812] Listener at /users/klvexHq3GOQ4IiWpOs4WP7H4pmy1/items failed: permission_denied
  </code></pre>
  
  <p>First i thought this would be because i am not yet signed in. So i tried signing in immediately after the sign up and then add data to the database but still the same error.
  Please help me with this. I am really stuck here.</p>