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

Parsing cookies returns empty object {} instead of null #5523

Closed
1 task done
xriter opened this issue Feb 20, 2023 · 1 comment
Closed
1 task done

Parsing cookies returns empty object {} instead of null #5523

xriter opened this issue Feb 20, 2023 · 1 comment

Comments

@xriter
Copy link

xriter commented Feb 20, 2023

What version of Remix are you using?

1.13.0

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

// const cookies = request.headers.get("Cookie") ?? "";
// to reproduce, this the header string:
const cookies = "inspectorSessionId=ctinspectorlogin; __stripe_mid=79bda20b-3e18-405b-8db6-2d7829fce613d27550; team=a; uuid=63e90dfdf255f; contributorId=c08fb47c-c438-4cb9-b3fe-3214d4437d39; loginSessionId=a0116336-488d-4ecd-9555-ba99f6e1d7da; organizationId=cld98h5jd0000zqm85wvj7wev";

const loginSessionId = (await createCookie("loginSessionId").parse(cookies)) ?? "";

console.log(loginSessionId); // gives {} instead of "a0116336-488d-4ecd-9555-ba99f6e1d7da"

Is it a particular problem with this header string?

Expected Behavior

The cookie.parse() function should return the cookie string from the header, or at least null if not found. Not {}.

Actual Behavior

The cookie.parse() function returns an empty object {} instead of null or the actual value of the cookie.

@vpfaulkner
Copy link

@xriter I ran into this today and it seems that "cookie must be base64 encoded if you want the Remix cookie utils to parse it" according to this Remix discord discussion: https://discord.com/channels/770287896669978684/1070450652049834159/1070460981207117897

In my case, I want to read a cookie that has been set by the client and couldn't do so using cookie.parse https://remix.run/docs/en/main/utils/cookies#md-cookieparse (which is confusing IMO)

Here's the source code: https://github.com/remix-run/remix/blob/main/packages/remix-server-runtime/cookies.ts#L180

phollome added a commit to mint-vernetzt/community-platform that referenced this issue Feb 13, 2024
cookie.parse method seems to only accept base64 encode values
see remix-run/remix#5523 (comment)
nac62116 pushed a commit to mint-vernetzt/community-platform that referenced this issue Feb 13, 2024
cookie.parse method seems to only accept base64 encode values
see remix-run/remix#5523 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants