title: Firebase Database Security Rules - Allow access to friends
body: <p>I am trying to give read access to posts made by a user based on the user being a friend of the author. However, Firebase tells me &quot;variable unknown $friendId&quot;. Here are my</p>
  <pre><code>rules:
  
  users&quot;: {
        &quot;$uid&quot;: {
          &quot;.read&quot;: &quot;$uid === auth.uid&quot;,
          &quot;.write&quot;: &quot;$uid === auth.uid&quot;,
            &quot;posts&quot;: {
              &quot;public&quot;: {
                &quot;.read&quot; : &quot;auth != null&quot;
              },
                &quot;private&quot; : {
                  &quot;.read&quot;: &quot;root.child('users').child($uid).child('friends').child($friendId) === auth.id&quot;
                }
            }
        }
  </code></pre>
  <p>Basically, I want Firebase to check if /users/$uid/friends/ contains the friends Id and give permission to read /users/$uid/posts/private if that is the case.</p>