-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: extract local credentials into a new model #385
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff. Just a few comments and questions. :)
packages/shopping/src/repositories/user-credentials.repository.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bajtos Thank you very much for creating the PR 👍 mostly LGTM, left a few comment.
required: true, | ||
mongodb: {dataType: 'ObjectID'}, | ||
}) | ||
userId: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why do we need an extra userId when id
is already defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id
is the primary key ofUserCredentials
modeluserId
is 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my most recent comment. thx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
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š <[email protected]>
e27afa7
to
4a180bb
Compare
Introduce
UserCredentials
models to hold hashed passwords, add has-one relation fromUser
toUserCredentials
.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.