-
Notifications
You must be signed in to change notification settings - Fork 66
Update for hapi 17.x.x #61
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
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.
That's all I could find, didn't review the tests that deeply.
README.md
Outdated
|
||
const main = async () => { | ||
|
||
const server = new Hapi.Server({ port: 4000 }); |
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.
No new
.
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.
👍
@@ -31,22 +33,47 @@ const users = { | |||
} | |||
}; | |||
|
|||
const validate = function (request, username, password, callback) { | |||
const validate = async (request, username, password, h) => { |
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.
What's the point of h
if you're not using it ? Should there be an example with it being used ?
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.
I'll remove it from here as it's not used. Don't need to show all functionality in the example.
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.
Is there any case where you would use it ?
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.
Yes, you can set the return object response
property to a custom response. Previously this was passed in the error position but it doesn't seem appropriate for it to be throw
n.
You would use h
to do something like:
return { response: h.redirect('http://hapijs.com') };
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.
May be worth of an example then ?
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.
Sure, added to the README: d6396b9
package.json
Outdated
"boom": "3.x.x", | ||
"hoek": "4.x.x" | ||
"boom": "7.x.x", | ||
"bounce": "^1.2.0", |
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.
Bounce not used ?
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.
👍
lib/index.js
Outdated
if (!authorization) { | ||
return reply(Boom.unauthorized(null, 'Basic', settings.unauthorizedAttributes)); | ||
return h.unauthenticated(Boom.unauthorized(null, 'Basic', settings.unauthorizedAttributes)); |
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.
If you are not also passing credentials, you can just throw the error.
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.
👍
lib/index.js
Outdated
|
||
credentials = credentials || null; | ||
try { |
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.
This try scope is far too big. Declare the try variables with var
and limit it to the one line.
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.
Correct me if I'm wrong but I don't think we need the try/catch at all then, if it's ok to just have the error rethrown in this scope.
lib/index.js
Outdated
|
||
credentials = credentials || null; | ||
try { | ||
const { isValid, credentials, takeover } = await settings.validate(request, username, password, h); |
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.
Maybe response
is a better variable name than takeover
given the overlap with a hapi api.
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.
Changed
Please set milestones... |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Would appreciate reviews from people more familiar with async/await etc to give feedback on the approach taken.
Main changes:
validateFunc
option tovalidate
err, isValid, credentials
to validateFunc callback it now returns an object or throws an errorerr
position (e/g/ to support redirects) has been supported here by instead returning atakeover
response
property of the return object. I did consider just having it return a response object but not sure there's a way to check if it is a response object in the scheme?Closes #60