I have 2 nodes in the realtime database, users and customers. Both of them are related by the the attribute company, which is one more node.
The users collection is as follows.
{
users: {
"2E6G3TCoBcONAh4Wt0TWMVcibgV2": {
"companyid": "-KyeTbr9N-xEdpPElgjx",
},
"5mAfDeQchdROHsmxUVy8AqruGKF2": {
"companyid": "-KyeTbr9N-xEdpPElgjx",
},
"6YoDdETq2He6kt5G3TE9RY0iLDr1": {
"companyid": "-KvzqkH6FPauk3Giea12",
}
}
}
The customers node is as follows.
customers: {
"-KyUi8lpt9kSYcT1ForR": {
"company": "-KyB8grqQDb1Bk23Ob9A",
},
"-KyUiKrcwLuxOh9SHru2": {
"company": "-Ky7cg9AMvVuFQLZzmyM",
},
"-KyUijwDpYQctATFRKU1": {
"company": "-KyB8grqQDb1Bk23Ob9A",
}
}
The idea is that the user only gets to see the customers of his company. For this, the auth rule I put is
{
"rules": {
".read": false,
".write": false,
"users" : {
".read": "auth != null",
".write": "auth != null"
},
"customers": {
"$uid": {
".read": "root.child('users').child(auth.uid).child('companyid').val() == data.child('company').val()"
}
}
}
}
however, after this I still am not able to get the data from the database. When I do a query with the angularfire2 sdk, it does not return any value.
I need help regarding this. Thanks in advance.
Edit:
This is the code I am using to read data from the database.
getallCustomers() {
console.log("Getting all the Customers.");
return this.afDB.database.ref('customers');
}