honojs / honox

HonoX - Hono based meta framework
https://hono.dev
MIT License
1.66k stars 44 forks source link

Unable to use cookies through `hono/cookie` #209

Open driedpampas opened 3 months ago

driedpampas commented 3 months ago

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 commented 3 months ago

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

driedpampas commented 3 months ago

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

driedpampas commented 3 months ago

It has started happening again with the same exact errors.