fastify / csrf-protection

A fastify csrf plugin.
Other
151 stars 19 forks source link

Bug in type definition #147

Closed hobi9 closed 1 year ago

hobi9 commented 1 year ago

Prerequisites

Fastify version

4.23.2

Plugin version

6.4.0

Node.js version

20.9.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.1

Description

Hi, when using typescript and trying to register the csrf-protection plugin, i get a compiler error because csrfOpts.hmacKey is not defined even though on the docs and on the javascript code that property is required only if the sessionPlugin is fastify/cookie and csrfOpts.userInfo is truthy.

  if (sessionPlugin === '@fastify/cookie' && csrfOpts.userInfo) {
    assert(csrfOpts.hmacKey, 'csrfOpts.hmacKey is required')
  }

Steps to Reproduce

  await fastify.register(Csrf, {
    sessionPlugin: '@fastify/cookie',
    cookieOpts: {
      signed: true,
    },
  });

Expected Behavior

I would expect to be able to register the plugin without any compiler errors.

Uzlopak commented 1 year ago

Are you willing to provide a PR?