Closed Arnesfield closed 1 year ago
4.13.0
6.1.0
18.14.2
Linux
Ubuntu 22.04.2 LTS
The return type of the decorated generateCsrf method is FastifyReply: https://github.com/fastify/csrf-protection/blob/a48195429b0cf6fd7b233a096d35810338cc90bc/types/index.d.ts#L17-L19
generateCsrf
FastifyReply
Looking at the code, the generateCsrf methods return tokens.create() which is a string.
tokens.create()
string
Not a big issue as the token is almost always returned or used in reply.send(), but it would be nice to have the type fixed.
reply.send()
Example:
const fastify = require('fastify')(); fastify.register(require('@fastify/cookie')); fastify.register(require('@fastify/csrf-protection')); fastify.get('/', (_, reply) => { const token = reply.generateCsrf(); const type = typeof token; console.log('token type:', type); // type is 'string' return { token, type }; }); fastify.listen().then(address => { console.log('listening on', address); });
The value of typeof token is string but the token type (hovering in VSCode) is FastifyReply.
typeof token
token
Return type of generateCsrf method should be a string instead of FastifyReply.
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.
Prerequisites
Fastify version
4.13.0
Plugin version
6.1.0
Node.js version
18.14.2
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Ubuntu 22.04.2 LTS
Description
The return type of the decorated
generateCsrf
method isFastifyReply
: https://github.com/fastify/csrf-protection/blob/a48195429b0cf6fd7b233a096d35810338cc90bc/types/index.d.ts#L17-L19Looking at the code, the
generateCsrf
methods returntokens.create()
which is astring
.Not a big issue as the token is almost always returned or used in
reply.send()
, but it would be nice to have the type fixed.Steps to Reproduce
Example:
The value of
typeof token
isstring
but thetoken
type (hovering in VSCode) isFastifyReply
.Expected Behavior
Return type of
generateCsrf
method should be astring
instead ofFastifyReply
.