title: Fastify REST-API JWT-Auth Plugin not firing as preHandler
body: <p>Im setting up a Fastify Rest-Api and wrote a Plugin to encapsulate my authentication logic which is based on JWT. Im using the preHandler Hook on each route that i want to protect but it seems that the preHandler or my plugin just gets ignored since i can just make a request without a token at all and get the data. </p>
  
  <p>I looked up every piece of documentation but still cannot get it running. If i just console.log() my function fastify.authenticate i get an undefined.</p>
  
  <p><strong>This is my plugin customJwtAuth:</strong></p>
  
  <pre><code>const fp = require('fastify-plugin')
  
  async function customJwtAuth(fastify, opts, next) {
  
  //register jwt 
   await fastify.register(require('fastify-jwt'),
      {secret: 'asecretthatsverylongandimportedfromanenvfile'})
  
  fastify.decorate('authenticate', async function(request, reply) {
   try {
     const tokenFromRequest = request.cookies.jwt
  
    await fastify.jwt.verify(tokenFromRequest, (err, decoded) =&gt; {
       if (err) {
         fastify.log.error(err)
         reply.send(err)
      }
       fastify.log.info(`Token verified: ${decoded}`)
    })
    } catch (err) {
    reply.send(err)
    fastify.log.error(err)
    }
   })
  next()
  }
  
  module.exports = fp(customJwtAuth, {fastify: '&gt;=1.0.0'})
  </code></pre>
  
  <p><strong>I register this plugin like this in my main server.js file:</strong></p>
  
  <pre><code>  const customJwtAuth = require('./plugin/auth')
    fastify.register(customJwtAuth).after(err =&gt; {if (err) throw err})
  </code></pre>
  
  <p><strong>Then i apply my function like this to the routes:</strong></p>
  
  <pre><code>const fastify = require('fastify')
  const productHandler = require('../handler/productHandler')
  
  const productRoutes = [
    {
    method: 'GET',
    url: '/api/product',
    preHandler: [fastify.authenticate],
    handler: productHandler.getProducts
    }, ... ]
  </code></pre>
  
  <p>The api shouldnt return any Data if the request doesnt include a signed jwt or without a jwt at all.</p>