Following the documentation I am trying to register the fastify secure session, but for some reason I am getting an error regarding the type of the fastify secure session middleware.
The code in the main.ts:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { ConfigService } from '@nestjs/config';
import { ValidationPipe } from '@nestjs/common';
import session from '@fastify/secure-session';
import { session_key } from '@app/keys';
(async () => {
const app = await NestFactory.create\<NestFastifyApplication\>(AppModule, new FastifyAdapter());
const config = app.get(ConfigService);
const { port } = config.get('http');
app.useLogger(config.get('loglevels'));
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
app.enableShutdownHooks();
app.register(session, { secret: 'asdawdasadgfhafjwefihdauhadiwudhaadoiuahwdasiefuhasefiu', salt: 'asdawdafowsuFIU' });
await app.listen(port);
})();
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.
Type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>' is missing the following properties from type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>': serializeCookie, parseCookie, createSecureSession, decodeSecureSession, and 3 more.
14 | app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
15 | app.enableShutdownHooks();
> 16 | app.register(session, { key: 'asdawdasadgfhafjwefihdauhadiwudhaadoiuahwdasiefuhasefiu', salt: 'asdawdafowsuFIU' });
| ^^^^^^^
17 | await app.listen(port);
18 | })();
19 |
According to the docs, everything should be fine...
The problem was the version of the
@nestjs/platform-fastify.Upgrading to version
10.3.1solves the type inconsistency.