import { getContext, getContextData } from "waku/middleware/context"; import cookie from "cookie"; const useCookies = () => { const ctx = getContext(); const headers = ctx.req.headers; const getCookie = (name: string) => { const cookieHeader = headers.cookie; if (!cookieHeader) return null; const cookies = cookie.parse(cookieHeader); return cookies[name]; }; const setCookie = (value: string) => { const ctxdata = getContextData(); // Set cookie with proper attributes for security and functionality ctxdata.cookie = `sorlang=${value}; Path=/; HttpOnly; SameSite=Lax; Max-Age=2592000`; console.log("Cookie value being set:", value); }; const delCookie = (name: string) => { const ctxdata = getContextData(); // Set an expired cookie to delete it ctxdata.cookie = `${name}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT`; }; return { getCookie, setCookie, delCookie }; }; export { useCookies };