I am trying to read the value from firebase in my ionic app using the angularjs framework. I have the existing getPlayer function below that works fine for returning the object stored for a specific user. I am able to read key value pairs within that object.
// Data Service
.factory('dataService', ['$firebase', 'config', function ($firebase, config) {
// Get Firebase reference
var dataRef = new Firebase(config.firebaseUrl);
// Get the Firebase object
return $firebase(dataRef);
}]);
Here is the getPlayer function that returns an object fine.
var users = dataService.$child('users');
var getPlayer = function(playerId) {
return users.$child(playerId);
};
I am trying to implement firebase security rules so I don't want users to get all the information of a user using the above function. I wrote the firebase rules to allow getting the specific key 'fullname' in a player's object under users. I tested the authorization rules in the firebase simulator to query /users/{playerid}/fullname and it works fine.
Here is the relevant firebase db structure from the security rules
{
"rules": {
"users": {
"$uid": {
".read": "auth != null && auth.uid == $uid",
"friends": {".read": "auth != null"},
"fullname": {".read": "auth != null"}
}
}
}
}
I then try the below function which only returns {"$id:"fullname"}
var getPlayerFullname = function(playerId) {
console.log(users.$child(playerId).$child('fullname'));
return users.$child(playerId).$child('fullname');
};
When I inspect the console log in chrome I see the following which shows the value I am looking for in the '$value' key.