title: How users can only see their own data in Cloud Firestore?
body: <p>I'm building an app with Kotlin. In the app, the user can sign up and log in. After the user log in, the user adds some text and pictures, and these data is successfully added to the firebase cloud store and displayed in the app as a list. However, this list can be accessed by anyone registered on the app.</p>
  <p>What I want to do is how users can only see their own data. So I don't want users to see each other's data. I just want every user to see their own added data. I think that I need to change Firebase Cloud Strore rules and I think userId must be equal to documentId to make it. But How can I do it ?</p>
  <p>I'm new about this, Thank you !</p>
  <p>Cloud Firestore Rules ;</p>
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
      // Allow only authenticated content owners access
      match /Notes/{userId}/{documents=**} {
        allow read, write: if request.auth != null &amp;&amp; request.auth.uid ==userId
      }
    }
  }
  </code></pre>
  <p><img src="https://i.stack.imgur.com/f1esi.png" alt="My cloud firestore screenshot " /></p>
  <p>and I save useremail, noteTitle ...ect. to the database as I shared ;</p>
  <pre><code>val noteMapElse = hashMapOf&lt;String, Any&gt;()
  
              noteMapElse.put(&quot;userEmail&quot;, auth.currentUser!!.email.toString())
              noteMapElse.put(&quot;noteTitle&quot;, titleText.text.toString())
              noteMapElse.put(&quot;yourNote&quot;, noteText.text.toString())
              noteMapElse.put(&quot;date&quot;, Timestamp.now())
  
  
  
              //UUID -&gt; Image Name
  
              val uuid = UUID.randomUUID()
              val imageName = &quot;$uuid.jpg&quot;
  
              val storage = FirebaseStorage.getInstance()
              val reference = storage.reference
              val imagesReference = reference.child(&quot;images&quot;).child(imageName)
  
              imagesReference.putFile(selectedPicture!!).addOnSuccessListener { taskSnapshot -&gt;
  
                  // take the picture link to save the database
  
                  val uploadedPictureReference =
                      FirebaseStorage.getInstance().reference.child(&quot;images&quot;).child(imageName)
                  uploadedPictureReference.downloadUrl.addOnSuccessListener { uri -&gt;
                      val downloadUrl = uri.toString()
                      println(downloadUrl)
  
                      noteMapElse.put(&quot;downloadUrl&quot;, downloadUrl)
  
                      db.collection(&quot;Notes&quot;).add(noteMapElse).addOnCompleteListener { task -&gt;
                          if (task.isComplete &amp;&amp; task.isSuccessful) {
  
                              finish()
                          }
  
  
                      }.addOnFailureListener { exception -&gt;
  
                          Toast.makeText(
                              applicationContext,
                              exception.localizedMessage?.toString(),
                              Toast.LENGTH_LONG
                          ).show()
  
                      }
  
                  }
  
  
              }
  
  
          }
  </code></pre>
  <p>This is also my sign in and sign up activity;</p>
  <pre><code>fun signIn (view: View) {
  
          auth.signInWithEmailAndPassword(mailText.text.toString(), passwordText.text.toString())
              .addOnCompleteListener { task -&gt;
  
                  if (task.isSuccessful) {
  
                      Toast.makeText(applicationContext, &quot;Welcome : ${auth.currentUser?.email.toString()}&quot;,
                          Toast.LENGTH_LONG).show()
                      val intent = Intent(applicationContext, ListViewActivity::class.java)
                      startActivity(intent)
                      finish()
                  }
  
              }.addOnFailureListener { exception -&gt;
                  Toast.makeText(
                      applicationContext,
                      exception.localizedMessage?.toString(),
                      Toast.LENGTH_LONG
                  ).show()
  
              }
  
      }
  
  
      fun signUp (view: View) {
  
          val email = mailText.text.toString()
          val password = passwordText.text.toString()
  
  
          auth.createUserWithEmailAndPassword(email,password).addOnCompleteListener {
  
              if (it.isSuccessful) {
  
                  Toast.makeText(applicationContext, &quot;Your Account Has Been Created Successfully&quot;, Toast.LENGTH_LONG).show()
  
                  val intent = Intent(applicationContext, ListViewActivity::class.java)
                  startActivity(intent)
  
                  finish()
  
              }
  
          }.addOnFailureListener { exception -&gt;
  
              if (exception != null ) {
  
                  Toast.makeText(applicationContext,exception.localizedMessage.toString(),Toast.LENGTH_LONG).show()
  
              }
  
          }
  
  
      }
  
  }
  </code></pre>