Let's say I have a social app where users connect with friends on their contacts to do something. How do those users find each other? See their e-mails? So far no user can see another user. What is the best way to do this? This specific need is not anywhere in the documentation that I can find and on Stackoverflow this question gets downvoted by trolls for no apparent reason. It's not answered in the documentation that I can find anywhere. I've looked and searched and searched Google. I don't know if I'm looking for it wrong or what.
If I GET the user model whether it's extended to a model called people or whether I just use the built in user model, I get this error when I query from the explorer using the GET method on my person model:
{
"error": {
"name": "Error",
"status": 401,
"message": "Authorization Required",
"statusCode": 401,
"code": "AUTHORIZATION_REQUIRED",
"stack": "Error: Authorization Required at... }
}
It doesn't even matter if I add this to the person.json in the model (and I'm not even sure if I should be doing this):
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "__get__People",
"model": "Person"
},
What is the problem here? What is recommended? How do users connect with each other in Loopback?
{
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "findEmailAddresses"
}
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "__get__People",
"model": "Person"
},
module.exports = function(Person) { Person.getPrefs = function(personId, cb) { Person.findById(personId,{ include: [{ relation: 'foodPrefs', scope: { include: { relation: 'food_pref_to_food_type' } } }] }, function(err, personFound) { if (err) { return cb(err); }
cb(null, personFound); }); }
Person.findEmailAddresses = function(cb) { Person.find(function(err, peopleFound) { if (err) { return cb(err); } cb(null, peopleFound); }); }
Person.remoteMethod( 'getPrefs', { http: {path: '/:personId/getPrefs', verb: 'get'}, accepts: [{arg: 'personId', type: 'number'}], returns: {arg: 'type', type: 'object'}, description: ['a person object'] } );
Person.remoteMethod( 'findEmailAddresses', { http: { path: '/:Person', verb: 'get' }, returns: [{ arg: 'email', type: 'array' }], description: ['all emails'] } );
};
{
"email": [
{
"fname": "Me",
"lname": "You",
"email": "m...@home.com",
"id": 1
},
{
"fname": "Lazy",
"lname": "Bastard",
"email": "la...@home.com",
"id": 2
},
{
"fname": "Bored",
"lname": "Athome",
"email": "bo...@home.com",
"id": 3
}
]
}
Person.findEmailAddresses = function(cb) {
Person.find([ { fields: { email: true } } ], function(err, peopleFound) {