title: How to check if user with the email entered by user on the login form exists or not in firebase
body: <p>It's my first time I am working with firestore db. So I have this User class in my app:</p>
  
  <pre><code>data class User(
      val name: String,
      val email: String,
      val standard: String,
      val formNum: String,
      val isVerified: Boolean = false
  )
  </code></pre>
  
  <p>Every time a new user registers, it save the data to the firestore database.
  I want to query when the user clicks the login button, but <strong>before they are actually signed in</strong>, if a user with that email exists or not. I use the following code:</p>
  
  <pre><code>db.collection(User.USERS_DB_NAME)
              .whereEqualTo("email", email.text.toString())
              .get()
              .addOnSuccessListener {
                  if (it.size() == 0)
                  {
                      Log.d(TAG, "Email not found")
                      email.error = getString(R.string.error_invalid_email)
                  }
              }
  </code></pre>
  
  <p>However in the log, it gives warning as:</p>
  
  <blockquote>
    <p>W/Firestore: (19.0.2) [Firestore]: Listen for Query(users where email == email@example.com) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}</p>
  </blockquote>
  
  <p>Here is my rule:</p>
  
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
      match /users/{user} {
        allow read, write: if request.auth != null &amp;&amp; user == request.auth.uid;
      }
    }
  }
  </code></pre>
  
  <p>How do I modify my rules to allow this query? Or my way of structuring the data is wrong? Please suggest the best way to solve this.</p>