pillarjs / cookies

Signed and unsigned cookies based on Keygrip
MIT License
1.29k stars 152 forks source link

TypeError: Cannot read property 'encrypted' of undefined #143

Closed denismart closed 2 years ago

denismart commented 2 years ago

Running with Next.js on localhost and getting: TypeError: Cannot read property 'encrypted' of undefined

Here is fragment of code:

const cookies = new Cookies(context.req, context.res);
cookies.set(process.env.COOKIE_NAME, cryptedString, { maxAge: COOKIE_LIFE_IN_MS });
dougwilson commented 2 years ago

Hello @denismart sorry you are having trouble. I am not 100% familiar with Next.js, but that error would indicate that whatever context.req refers to is not an actual Node.js HTTP IncomingMessage object. This module expects the first argument to be an IncomingMessage object.