-
-
Notifications
You must be signed in to change notification settings - Fork 29
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: explicit hook configuration via addHook
#212
base: main
Are you sure you want to change the base?
Conversation
hook
optionaddHook
2d0bde0
to
df801c0
Compare
Co-authored-by: KaKa <[email protected]> Signed-off-by: Frazer Smith <[email protected]>
Co-authored-by: KaKa <[email protected]> Signed-off-by: Frazer Smith <[email protected]>
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.
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
Readme.md:83
- The
addHook
option description is duplicated. Please remove the redundant description.
* `addHook`: If `false`, this plugin will not register any hook automatically. Instead, it provides two decorations: `fastify.verifyBearerAuth` and `fastify.verifyBearerAuthFactory`. If `true` or nullish, it will default to `onRequest`. You can also specify `onRequest` or `preParsing` to register the respective hook
lib/errors.js:6
- The error message for FST_BEARER_AUTH_INVALID_HOOK is clear and helpful.
const FST_BEARER_AUTH_INVALID_HOOK = createError('FST_BEARER_AUTH_INVALID_HOOK', 'options.addHook must be either "onRequest" or "preParsing"')
Readme.md
Outdated
* `addHook`: If `false`, no hook is registered automatically, and instead the `fastify.verifyBearerAuth` and `fastify.verifyBearerAuthFactory` decorators are exposed. | ||
If `true` or nullish, defaults to `onRequest`. `onRequest` or `preParsing` can also be used to register the respective hook |
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 text does not make it clear to me that it accepts the strings "onRequest" and "preParsing" to specify the hook to be used. It wasn't until I was reviewing the code changes that I understood the selection is meant to be provided here.
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.
Supersedes #207.
This PR updates the
addHook
option to allow the hook type to be explicitly configured to be eitheronRequest
orpreParsing
.The hooks are limited to these two values so that developers cannot open themselves up to DoS attacks.
If the option is nullish or true it defaults to
onRequest
, which is its original functionality.Checklist
npm run test
andnpm run benchmark
and the Code of conduct