-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Encode isn't an option in Cookie #64346
Comments
Yeah, I'm having the same error in my codebase. Lost hours. |
I ended up creating route handlers (API) so I can serialize the cookies and set them in my response header. |
Same issue here, would be useful to have a way to specify custom "encode" function whenever we don't want to use |
We're looking into this particular use case now. It may be possible to modify the encode property in the future for the Bear in mind that RFC2109 requires that the cookie value either be a:
This would mean that if the user sets a cookie via |
@wyattjoh any updates on this? We're having to create an api route to set cookies for a client because their backend doesn't decode the cookie string before ingesting. Frustrating and I'm hoping to get them to update their code but if the cookies().set() method would allow us to override the encoding that would be super helpful Thanks! |
I was able to work around this issue by manually appending the Set-Cookie header instead of using response.headers.append(
"Set-Cookie",
`${cookie.name}=${cookie.value}; Path=/; HttpOnly; Secure; SameSite=None;`,
); |
Docs say it's available now https://nextjs.org/docs/app/api-reference/functions/cookies |
Taking a quick glance it seems this is not implemented yet for the |
Link to the code that reproduces this issue
https://github.com/c0d3rm0n/test-set-cookies
To Reproduce
I'm creating an app that uses third party libraries that use Go and set / send their cookies in raw format, and they expect to receive them in the same format.
I use those services in my server actions, and then I have to set the cookies they send inside of response headers. As result of this action, the cookie(s) sent to my server will be set in my browser.
However, the function cookies().set({...my_cookie}) from next/headers will encode the cookie and the value set will not match the original one, causing my calls to those 3rd party libs to fail or give error.
From what I could find, encode should be an option of Cookie, and in next.js modules it is possible to find an interface that includes it (CookieSerializeOptions) but then, the other interfaces that use it don't include encode... So, even if I try to set a cookie like cookies().set({...my_cookie, encode: String}) the browser record will be encoded.
The same happens in Middleware, using nextResponse.cookies.set({...my_cookie}).
Current vs. Expected behavior
I would like to be able to set a cookie and define the encoding function in it's options.
For example, the function cookies().set({...my_cookie, encode: String}) should accept encode as option and save a value like
qwerty123=
and not
qwerty123%3D
as it is saving at the moment...
Provide environment information
Which area(s) are affected? (Select all that apply)
Middleware / Edge (API routes, runtime)
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: