Chi Hao
Chi Hao
Explore posts from servers
HHono
Created by Chi Hao on 6/4/2024 in #help
unable to retrieve cookie value
// index.ts
import { Hono } from 'hono';
import { getCookie, setCookie} from 'hono/cookie';
import CryptoJS from 'crypto-js';

const app = new Hono();

app.get('/csrf', (c) => {
setCookie(c, 'X-CSRF-Token', 'abc');
const testget = getCookie(c, 'X-CSRF-Token');
console.log('test get: ', testget);

const allCookies = getCookie(c);
console.log('allCookies : ', allCookies);

return c.text(csrfToken);
});

export default app;
// index.ts
import { Hono } from 'hono';
import { getCookie, setCookie} from 'hono/cookie';
import CryptoJS from 'crypto-js';

const app = new Hono();

app.get('/csrf', (c) => {
setCookie(c, 'X-CSRF-Token', 'abc');
const testget = getCookie(c, 'X-CSRF-Token');
console.log('test get: ', testget);

const allCookies = getCookie(c);
console.log('allCookies : ', allCookies);

return c.text(csrfToken);
});

export default app;
this is the log
test get: undefined
allCookies : {}
[wrangler:inf] GET /csrf 200 OK (8ms)
test get: undefined
allCookies : {}
[wrangler:inf] GET /csrf 200 OK (8ms)
41 replies