-
-
Notifications
You must be signed in to change notification settings - Fork 931
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
Extend model object with request context #462
Extend model object with request context #462
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.
Looks good, just two things:
a) Pleasechange this PR to a merge request to the dev
branch instead of `master.
b) Please add some tests with regards to setting and accessing the request context from model methods.
Great, if you add some tests I think we can merge this. |
Unit and integration tests are added! Thanks @mjsalinger for reviewing! |
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.
LGTM
…-request Extend model object with request context
Extend model object with request context
I don't think this works as expected as the model functions can be executed asynchronously, the request as set here could be overwritten during model execution. For example: const model = {
request: false,
saveToken: function (num) {
console.log(`saveToken for request ${num} start - model.request = ${model.request}`)
setTimeout(() => {
console.log(`saveToken for request ${num} end - model.request = ${model.request}`)
}, 2000);
}
}
// 1st request received 1 second after start
setTimeout(() => {
model.request = 1
model.saveToken(1);
}, 1000);
// 2nd request received 2 seconds after start
setTimeout(() => {
model.request = 2
model.saveToken(2);
}, 2000);
console.log('Starting - All requests queued'); Prints:
This was also pointed out in #564 (review). This will be removed from v3.1 and discussion can continue in #254 |
Problem:
There are many cases where you want to pass some parameters and access them in the model methods but you're only limited to the method signature params usually some attribute inside the
request
object. After going through some similar-issues (#254, #336) and PRs (#320) found out there are a lot of usecases needed for different people implementing this lib.Example:
In
saveToken
method I need to pass and saveconsentId
attribute in the token table from the request body, as follow:Suggested solution (Quick-win):
Extend
model
object withrequest
context in the handlers (authorize
,authenticate
,token
) so that it can be accessible in any of the model methods, also it won't break the current tests.Note:
Right now, I forked the lib and did this minimal change as a quick-win but it'd be better if this issue is fixed on the lib so I still can refer to the original lib no my forked one.
Any feedback or change requests are welcome! Thanks!