title: Unqiue usernames in firebase with no work arounds
body: <p>I've looked at other answers but I'm still confused. Basically I have a firebase auth system and am trying to enforce unique usernames.</p>
  <p>So far, I have 2 collections, a <code>users</code> collection and a <code>username</code> collection. Inside the users collection the documents contain user info. Inside the usernames collection each document id is the username and inside the documents are the userId.</p>
  <p>To prevent duplicate usernames on user signup I was thinking to make a query to usernames collection and check if the username exists, from there either display an error to the user or continue with sign up.</p>
  <p>code:</p>
  <pre><code>// Check if user exists
  
  const usernamesRef = collection(db, 'usernames');
  const usernameExists = query(usernamesRef, where('usernames', '==', username));
  
  if(usernameExists) {
    // handle error
  } else {
    createUserWithEmailAndPassword(auth, email, password)
    //
  }
  </code></pre>
  <p>My question is that is there any way to circumvent this, or is there a better way to do this. I've never done something like this before so I'm looking for input / suggestions. Thanks.</p>