strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.23k stars 1.2k forks source link

Can't login with extended User model. Get 401 Unauthorized #2122

Closed markgargan closed 8 years ago

markgargan commented 8 years ago

Posted to SO at http://stackoverflow.com/questions/35785233/extending-builtin-user-in-strongloop

I have created a Musician model in Strongloop that extends the in-built User model.

The generated lb-services.js client service allows me to create a new Musician instance however when I attempt to login I get a 401 unauthorized error? However if I make the builtIn User create and login with the generated User service I can do it fine?

What is the best practice for creating an extended user model in strongloop where the user may take on multiple guises in different areas of the system? have a number of different identities within the system? I.e. a user is a Musician and Musician is the base model for a Guitarist/Bassist/drummer?

Each of the different User types would have different parameters?

markgargan commented 8 years ago

Also I have the following remote hook in my musician.js file

module.exports = function (Musician) {

//send verification email after registration Musician.afterRemote('create', function (context, Musician, next) { console.log('> Musician.afterRemote triggered'); }

which is never called?

gkTim commented 8 years ago

For different access rights you should use roles instead of different user models. See: https://docs.strongloop.com/display/public/LB/Controlling+data+access

Check if the acl of the model is correct. You can find the default acl of the user model here: https://github.com/strongloop/loopback/blob/master/common/models/user.json

Also I would recommend you to enable acl debugging to find the error: See: https://docs.strongloop.com/display/public/LB/Setting+debug+strings

Hope this tipps help you to find the error.

richardpringle commented 8 years ago

@markgargan, did @gkTim's answer resolve you issue?

markgargan commented 8 years ago

@richardpringle @gkTim Hi folks, I believe that the ACL might sort me out but my codebase currently isn't in a position to try it out. I believe this will fix it though so I'd be happy to mark this as an answer but I'm not sure how to do so?

Thanks, Mark.