Firebase android : make username unique : <p>Parse will shut down at the end of the year, so I decided to start using Firebase. I need to implement a register process with 3 fields : email, username, password (<strong>Email &amp; username</strong> must be unique for my app). </p>

<p>Since, Firebase is not providing an easy way to manage username like Parse, I decided to use only the email/password registration and save some additional data like username. Here is my users data structure :</p>

<pre><code>app : {
    users: {
       "some-user-uid": {
            email: "test@test.com"
            username: "myname"
       }
    }
}
</code></pre>

<p>But, what I want to do is to make the username unique and to check it before creating an account.
These are my rules :</p>

<pre><code>{
    "rules": {
        ".read": true,
        ".write": true,
        "users": {
            "$uid": {
                ".write": "auth !== null &amp;&amp; auth.uid === $uid",
                ".read": "auth !== null &amp;&amp; auth.provider === 'password'",
                "username": {".validate": "!root.child('users').child(newData.child('username').val()).exists()"}
            }
        }
   }
}
</code></pre>

<p>Thank you very much for your help</p>
