Updating a user's role

15 views
Skip to first unread message

Lisa Riggle

unread,
Jun 23, 2017, 4:00:50 PM6/23/17
to LoopbackJS
After a user is created, I can assign that user to a role with this bit of code in my 'after save' hook:

let roleMap = {
    principalType: app.models.RoleMapping.USER,
    principalId: context.instance.id
};
role.principals.create(roleMap, function (err, principal) {
    if (err) throw err;
});
 
What I am having issues doing is changing the role assigned to a user. Originally I thought replacing 'create' with 'createOrUpdate' or 'upsertWithWhere' might do the trick, but loopback tells me those functions don't exist on 'principals'.

Can someone point me in the right direction?

Thanks!
--Lisa

Reply all
Reply to author
Forward
0 new messages