fastify-secure-session icon indicating copy to clipboard operation
fastify-secure-session copied to clipboard

`FastifySecureSession` type is not compatible with `FastifyPluginCallback`

Open stampaaaron opened this issue 5 months ago • 1 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.5.0

Plugin version

8.2.0

Node.js version

24.0

Operating system

macOS

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

15.6

Description

When using the fastifySecureSession callback as a plugin for my nestjs fastify project, I get a typescript error:

Argument of type 'FastifySecureSession' is not assignable to parameter of type 'FastifyPluginCallback<SecureSessionPluginOptions | (SecureSessionPluginOptions & Required<Pick<SecureSessionPluginOptions, "sessionName">>)[]> | FastifyPluginAsync<...> | Promise<...> | Promise<...>'.
  Type 'FastifySecureSession' is not assignable to type 'FastifyPluginCallback<SecureSessionPluginOptions | (SecureSessionPluginOptions & Required<Pick<SecureSessionPluginOptions, "sessionName">>)[]>'.
    Types of parameters 'instance' and 'instance' are incompatible.

This is my main.ts file:

import { fastifySecureSession } from "@fastify/secure-session";
...
  await app.register(fastifySecureSession, {
    expiry: configService.get("session.expiry"),
    cookieName: configService.get("session.cookieName"),
    secret: configService.get("session.secret"),
    salt: configService.get("session.salt"),
    cookie: {
      path: "/",
      secure: true,
      sameSite: "none",
      expires: new Date(Date.now() + configService.get("session.expiry") * 1000),
    },
  });
...

I belief there is a mismatch between the fastify version 5.5 and this plugin.

Thanks for your support.

Link to code that reproduces the bug

Expected Behavior

No response

stampaaaron avatar Aug 13 '25 14:08 stampaaaron

I belief there is a mismatch between the fastify version 5.5 and this plugin.

This is indeed the case. The problem is because the type for fastifySecureSession are based on the fastify dependency, which is a devDependency, so the version 5.0.0 is used. The types for version 5.0.0 are not compatible with 5.5.0.

Maybe a solution would be to reference fastify as a peerDependency and not being too strict with the version.

openscript avatar Aug 17 '25 14:08 openscript