Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method generateCsrf return type should be a string instead of FastifyReply #124

Closed
2 tasks done
Arnesfield opened this issue Mar 1, 2023 · 1 comment · Fixed by #125
Closed
2 tasks done

Method generateCsrf return type should be a string instead of FastifyReply #124

Arnesfield opened this issue Mar 1, 2023 · 1 comment · Fixed by #125
Labels
good first issue Good for newcomers

Comments

@Arnesfield
Copy link
Contributor

Prerequisites

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

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 is FastifyReply:

generateCsrf(
options?: fastifyCsrfProtection.CookieSerializeOptions
): FastifyReply;

Looking at the code, the generateCsrf methods return tokens.create() which is a 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.

Steps to Reproduce

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.

Expected Behavior

Return type of generateCsrf method should be a string instead of FastifyReply.

@climba03003 climba03003 added the good first issue Good for newcomers label Mar 1, 2023
@mcollina
Copy link
Member

mcollina commented Mar 1, 2023

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants