-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Is there a way to disable hooks on specific route? #487
Comments
Just register those routes in a different context: fastify.register((instance, opts, next) => {
// authenticated routes
instance.addHook('preHandler', fastify.auth([fastify.verifyJWT])
fastify.route(/*...*/)
})
fastify.register((instance, opts, next) => {
// non-authenticated routes
fastify.route(/*...*/)
}) |
@jsumners thanks! |
We are always receptive to PRs that improve documentation. |
Closing this. |
i know this is old issue but i get same problem too, i solve with this fastify.addHook("preHandler", async (request, reply) => {
// some validation
return;
});
fastify.get(
"/getaddress",
{
schema: {
query: Joi.object()
.keys({
data1: Joi.string().required(),
})
.required()
},
validatorCompiler: ({ schema, params, method, url, httpPart }) => {
return data => schema.validate(data);
},
preHandler: async (request, reply, done) => {
// spesific validation
return;
}
}, |
this will invoke multiple hook functions instead skipping it. |
I'm trying to setup auth as per example from
fastify-auth
:But I need to have a couple of routes that shouldn't trigger the auth
preHandler
on them.Is there a way to disable this preHook for specific routes? Or maybe there's a different way of defining routes so that hook won't get executed?
The text was updated successfully, but these errors were encountered: