Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your PR but I think we have a problem with
setCookie
function and only on backend side.For example, if we run this code on frontend side everything will be ok
and
I think we need to figure out why a boolean value is set and not a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured it out a little and I think the problem is in line 109
It seems we need to use
stringify
functionlike in 132 line
What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review!🙌 I understand your perspective. In this PR (after my changes), setting cookies as a boolean or even another type like a number works correctly: the value is being set (server-side), and you can easily get it (server-side), but only with the same type as it was set with. Let's examine these examples:
Setters and getters use
cookies
fromnext/headers
and thereq
object fromNext.js
. They also behave accordingly.Therefore, my proposal is to merge this PR as a fix for setting values server-side and either modify the rest of the codebase to adhere to the native Next.js behavior or parse every type of value to string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for delay.
Cookies value is always string.
Your example works as you say because you try to set and to get cookies during one request
For example. Let's imagine two API endpoints
I think this behavior can lead unexpected results so better way is to always set string and always get string
Also, without "app router" this library transform value to string before setting. It will be better to keep the same behavior for different cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I got It! 🙌 I have submitted another PR where all values are set as strings. Please check it out and test it -> #69
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think this PR should be closed