title: Firebase Rules Using root
body: <p>Database:</p>
  
  <pre><code>"user_locations": { 
     "123": {
       "user_id": "kcf3566"
     }
  
  }
  </code></pre>
  
  <p>Rule:</p>
  
  <pre><code>"user_locations": { 
     "$loc_id": {
       ".read": "auth.uid == root.child('user_locations/$loc_id/user_id').val()",
       ".write": "auth != null"
     }
  
  }
  </code></pre>
  
  <p>Per the above code, I am trying to allow ONLY users with the with a matching uid at the path user_locations > $key > uid to be able to read the data. I tried the above rule, however, I am unable to access the data.</p>
  
  <p>The code that triggers the problem:</p>
  
  <pre><code>$scope.get_user_locations = function () {
  
      firebase.auth().onAuthStateChanged(function (user) {
          if (user) {
  
              var returned_locations = firebase.database().ref('user_locations/');
              returned_locations.on('value', function (snapshot) {
                  $scope.user_locations = snapshot.val();
              });
  
  
          } else {
              $state.go('login');
          }
      });
  
  };
  </code></pre>