title: User to access only his/her document in Firestore
body: <p>I'm struggling by setting the firestore rules.</p>
  
  <p>As per the screenshot, I have collection for the user with dynamic document IDs.</p>
  
  <p><a href="https://i.stack.imgur.com/Hu9K4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hu9K4.png" alt="enter image description here"></a></p>
  
  <p>I'm trying to set a rule for the user to access only his/her document.</p>
  
  <p>FbId is facebook id (since it is the authentication way in my app)</p>
  
  <p>userId is firebase id (not sure if it is important to save it or not)</p>
  
  <p>Here is my current rule:</p>
  
  <blockquote>
  <pre><code>match /users/{document=**} {
    allow read, write: if normalUser();
    }
  
    function normalUser() {
    return request.auth.token.firebase.sign_in_provider == "facebook.com"
    &amp;&amp; request.auth.uid != null;
  }
  </code></pre>
  </blockquote>
  
  <p>This rule gives access to the authenticated user for the whole collection.</p>
  
  <p>How can I set this rule? If there is anything I need to change in the structure?</p>
  
  <p>Update: I don't want to change the documentid for the user collection to match userid because I have another collection where the user could have multiple documents; so this solution won't fit everything.</p>
  
  <p>Thanks</p>