feat: extract local credentials into a new model#385
Conversation
emonddr
left a comment
There was a problem hiding this comment.
Great stuff. Just a few comments and questions. :)
packages/shopping/src/repositories/user-credentials.repository.ts
Outdated
Show resolved
Hide resolved
| required: true, | ||
| mongodb: {dataType: 'ObjectID'}, | ||
| }) | ||
| userId: string; |
There was a problem hiding this comment.
Hmm, why do we need an extra userId when id is already defined?
There was a problem hiding this comment.
idis the primary key ofUserCredentialsmodeluserIdis a foreign key referencing id of the user these credentials belong to
This is the classic HasOne/BelongsTo setup we use everywhere else in LB4.
It is possible to use User's id as the primary key of UserCredentials too, but we don't have first-class support for that in LoopBack yet.
Also note that depending on the password policy, we may want to store historical credentials and thus have more than on UserCredentials instance for a single user. Think of a password policy "the new value must be different than the last 3 values used".
Please look at https://loopback.io/doc/en/lb4/Authentication-Tutorial.html , and double-check that any code examples shown or instructions to post or get a user match what you now have. The |
emonddr
left a comment
There was a problem hiding this comment.
Adding a user with id specified fails. Please fix. thx. See my comment.
I find it very annoying that the documentation is depending on behavior that's not covered by automated tests :-/ I'll take a look and add the missing test. |
|
Thank you @emonddr for the pointers for documentation which I should check, this was very helpful 🙇 |
|
@bajtos Thank you,
You probably want to explain the |
|
Thank you all again for your feedback. I see the following major areas to improve:
Here is what I did:
|
As I mentioned in the PR referenced above, if we are not going to pass in an |
emonddr
left a comment
There was a problem hiding this comment.
See my most recent comment. thx.
Introduce `UserCredentials` models to hold hashed passwords, add has-one relation from `User` to `UserCredentials`. Rework authentication-related code to work with the new domain model. Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
e27afa7 to
4a180bb
Compare
Introduce
UserCredentialsmodels to hold hashed passwords, add has-one relation fromUsertoUserCredentials.Rework authentication-related code to work with the new domain model.
See loopbackio/loopback-next#1996 for additional information.
I have to say the code in the example app is a bit messy. Some things are (unnecessarily) duplicated in multiple places, therefore my pull request had to touch quite few files to update all duplications. Considering our current priorities, I am leaving refactoring & cleanup out of scope of my PR.