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

Unable to use cookies through hono/cookie #209

Open
driedpampas opened this issue Jul 27, 2024 · 3 comments
Open

Unable to use cookies through hono/cookie #209

driedpampas opened this issue Jul 27, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@driedpampas
Copy link

driedpampas commented Jul 27, 2024

What version of HonoX are you using?

0.1.23

What steps can reproduce the bug?

Case 1 - getCookie

import { getCookie } from 'hono/cookie'

const cookie = await getCookie(c, 'testCookie');
const test = !!cookie;

This error is thrown in the browser console:

Uncaught (in promise) TypeError: can't access property "raw", c.req is undefined
    getSignedCookie index.js:25

which points to this line const cookie = c.req.raw.headers.get("Cookie");


Case 2 - getSignedCookie

const cookie = await getSignedCookie(c, c.env.KEY, 'testCookie');
const test = !!cookie;

In development, bun throws and exits with:

TypeError: Cannot read properties of undefined (reading 'raw')
    at Module.getSignedCookie (/home/astra/Documents/database/honox-client/node_modules/hono/dist/helper/cookie/index.js:28:24)

Case 3 - setCookie

        setCookie(c, 'testCookie', '1')

This throws:

Uncaught (in promise) TypeError: c.header is not a function
    setCookie index.js:59

Which points to c.header("set-cookie", cookie, { append: true });


Case 4 - setSignedCookie

        seSignedCookie(c, KEY, 'testCookie', '1')

bun throws and exists with:

TypeError: c.header is not a function
    at Module.setSignedCookie (/home/astra/Documents/database/honox-client/node_modules/hono/dist/helper/cookie/index.js:82:5)
P.S: These snippets work perfectly in a Hono-only environment
@driedpampas driedpampas added the bug Something isn't working label Jul 27, 2024
@driedpampas driedpampas changed the title Unable to use cookies Unable to use cookies through hono/cookie Jul 27, 2024
@driedpampas
Copy link
Author

Update: I remembered removing the react-cookie package earlier, and sure enough, adding it fixed the errors. Sure is odd.

@driedpampas
Copy link
Author

And I removed it again and cookies still work fine. Will never figure out what happened.

@driedpampas
Copy link
Author

It has started happening again with the same exact errors.

@driedpampas driedpampas reopened this Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant