Giter VIP home page Giter VIP logo

Comments (6)

mediapolis avatar mediapolis commented on July 19, 2024 1

+1

from loopback-component-passport.

wprater avatar wprater commented on July 19, 2024 1

looks like this was never resolved?

from loopback-component-passport.

clockworkgr avatar clockworkgr commented on July 19, 2024

The problem is not so much in the model definitions as such since you could easily handle that by extending UserCredential and UserIdentity as well and overriding the relations to end up with your own Customer, CustomerIdentity, CustomerCredential for example.

This refers to the js model files as well as the json files since they are littered with hardcoded references,

So if you wanted the relation above to refer to a different (extended) User model with a different foreign key you would have to redefine the user relation in an extended Identity model with a different foreignKey and switch all the userId references in your Identity's js file.

Inefficient & Ugly but it is not the real problem so far. You could make sure that all your foreignKeys are the same as the original ones to not have to do that. Right?

Wrong!

The real problem is that loopback handles non-specified parameters to hasMany and belongsTo relations differently.

From the docs:

hasMany:
Foreign key: The camel case of the declaring model name appended with ‘Id’, for example, for model name "Customer" the foreign key is "customerId".

belongsTo:
Foreign key: The relation name appended with ‘Id’, for example, for relation name "customer" the default foreign key is "customerId".

This becomes a problem in PassportConfigurator.setupModels() where we have:

  if (!this.userModel.relations.identities) {
    this.userModel.hasMany(this.userIdentityModel, {as: 'identities'});
  } else {
    this.userIdentityModel = this.userModel.relations.identities.modelTo;
  }
  if (!this.userModel.relations.credentials) {
    this.userModel.hasMany(this.userCredentialModel, {as: 'credentials'});
  } else {
    this.userCredentialModel = this.userModel.relations.credentials.modelTo;
  }

Since loopback-component-passport does not define its own User model, we have to make sure that whatever our extended User model is, already contains the identities and credentials relations because the code above will lead to the foreignKeys for the two relations above to be {customUser}Id which obviously is not referenced anywhere in Identity and Credential models.

I stumbled upon this as well and I'm in the process of writing a patch to ensure that all references derive from the extended User Model name.

from loopback-component-passport.

clockworkgr avatar clockworkgr commented on July 19, 2024

#93

from loopback-component-passport.

jubbens avatar jubbens commented on July 19, 2024

@clockworkgr Any progress towards this? This seems like an absolutely colossal bug since the Loopback docs state

You must create your own custom model (named something other than "User," for example "Customer" or "Client") that extends the built-in User model rather than use the built-in User model directly. The built-in User model provides a great deal of commonly-used functionality that you can use via your custom model.

from loopback-component-passport.

clockworkgr avatar clockworkgr commented on July 19, 2024

@jubbens I've referenced my initial fix PR in the comment above...

Since then @jonathan-cassarubias has published a more polished version of the fix which is referenced here:#93 (comment)

Really have no idea why this hasn't been merged yet :/

from loopback-component-passport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.