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

Error when invoking setCookie on a new Request where cookies is undefined #76

Open
JonasDoe opened this issue Jul 10, 2024 · 0 comments

Comments

@JonasDoe
Copy link

JonasDoe commented Jul 10, 2024

If I create a new (fetch API) Request in a Next.js Route Handlers, e.g.

export async function GET(req: Request) {
  const myResponse = new Response('Hello, World', { status: 200, statusText: 'OK' });
  setCookie('myKey', 'myValue', { req, res: myResponse });
  return myResponse
}

this line of code in thecookies-next library will fail b/c res.cookies is undefined:

if (res) {
    res.cookies.set(payload); //  TypeError: Cannot read properties of undefined (reading 'set')
}

Curiously enough, there's no error if I just invoke setCookie('myKey', 'myValue', { res: myResponse }); (i.e. without res). But the Response won't bear any Set-Cookie entries then. Maybe I'm just misunderstanding the behavior of the library here?

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

No branches or pull requests

1 participant