Trouble with using `hono/cookie` helper with honox
Case 1 -
getCookie
getCookie
import { getCookie } from 'hono/cookie'const cookie = await getCookie(c, 'testCookie');const test = !!cookie;
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
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");
const cookie = c.req.raw.headers.get("Cookie");
Case 2 -
getSignedCookie
getSignedCookie
const cookie = await getSignedCookie(c, c.env.KEY, 'testCookie');const test = !!cookie;
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)
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
setCookie(c, 'testCookie', '1')
setCookie(c, 'testCookie', '1')
This throws:
Uncaught (in promise) TypeError: c.header is not a function setCookie index.js:59
Uncaught (in promise) TypeError: c.header is not a function setCookie index.js:59
Which points to
c.header("set-cookie", cookie, { append: true });
c.header("set-cookie", cookie, { append: true });
Case 4 -
setSignedCookie
setSignedCookie
seSignedCookie(c, KEY, 'testCookie', '1')
seSignedCookie(c, KEY, 'testCookie', '1')
bun
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)
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)