Skip to content

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

Merged
merged 5 commits into from
Nov 26, 2017
Merged

Update for hapi 17.x.x #61

merged 5 commits into from
Nov 26, 2017

Conversation

mtharrison
Copy link
Contributor

@mtharrison mtharrison commented Nov 11, 2017

Would appreciate reviews from people more familiar with async/await etc to give feedback on the approach taken.

Main changes:

  • Use of async/await
  • Rename of validateFunc option to validate
  • instead of returning err, isValid, credentials to validateFunc callback it now returns an object or throws an error
  • Previous ability to return a non-err error in err position (e/g/ to support redirects) has been supported here by instead returning a takeoverresponse 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

@mtharrison mtharrison added breaking changes Change that can breaking existing code dependency Update module dependency labels Nov 11, 2017
Copy link
Contributor

@Marsup Marsup left a 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 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new.

Copy link
Contributor Author

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) => {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

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 ?

Copy link
Contributor Author

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 thrown.

You would use h to do something like:

return { response: h.redirect('http://hapijs.com') };

Copy link
Contributor

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 ?

Copy link
Contributor Author

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bounce not used ?

Copy link
Contributor Author

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));
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@mtharrison mtharrison merged commit 222c98c into master Nov 26, 2017
@mtharrison mtharrison deleted the v17 branch November 26, 2017 03:51
@hueniverse
Copy link
Contributor

Please set milestones...

@mtharrison mtharrison added this to the 5. milestone Nov 26, 2017
@lock
Copy link

lock bot commented Jan 9, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes Change that can breaking existing code dependency Update module dependency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hapi 17
3 participants