question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Payload typing lost when using setCookie before

See original GitHub issue

Prerequisites

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

Fastify version

3.27.1

Plugin version

5.5.0

Node.js version

16.13.1

Operating system

Windows

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

11 (21H2)

Description

When using a schema for my route, I get payload typing. But when I use setCookie on my reply, the payload get the type unknown.

image image

Steps to Reproduce

type TSchemaResponse = {
    message: string
};

// ...
fastifyInstance.post<Response: TSchemaResponse>(
    "/hello",
    (request, reply) => {
        reply.send({message: 123}); // typescript error as message should be a string
    }
);
// ...
type TSchemaResponse = {
    message: string
};

// ...
fastifyInstance.post<Response: TSchemaResponse>(
    "/hello",
    (request, reply) => {
        reply
            .setCookie("hello", "there")
            .send({message: 123}); // no error (there should be an error)
    }
);
// ...

Expected Behavior

The payload should still be typed after calling setCookie (as setCookie should return “this” type)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
darkgl0wcommented, Feb 8, 2022

@hugoattal > thank you for the minimal reproducible example.

Thanks to this I was able to spot the cause of this issue. I will submit a PR to resolve this issue in a moment 😃

1reaction
hugoattalcommented, Feb 8, 2022

@darkgl0w Here it is: https://github.com/hugoattal/fastify-cookie-typing-bug-repro

Just run pnpm install (should also work with npm) and you can see the error under src/handler.ts

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set-Cookie - HTTP - MDN Web Docs
Indicates that the cookie is sent to the server only when a request is made with the https: scheme (except on localhost), and...
Read more >
Solved: Set-Cookie and Response Body not getting sent toge...
Goal: send three Set-Cookies header + response.content in response body. What I've tried: After some tests with AssignMessage, I realized that ...
Read more >
Set-Cookie not working in browser but works with Postman
I have implemented CORS configurations in my backend and frontend and all the other API requests work. However the Set-Cookie flag is not ......
Read more >
Axios ignoring set-cookie in cross-origin setup on Chrome ...
The bug. Axios 'with-credentials' does not seem to be abiding and setting the proper cookies under Chrome and Brave in NON-incognito mode.
Read more >
Set Cookie in Mock Service - Forums - IBM Support
The related processing rules does some processing and identity validation, generates an LTPAToken2 cookie and sets it for return to the client, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found