matthewmueller / next-cookies

Tiny little function for getting cookies on both client & server with next.js.
368 stars 17 forks source link

Fix TypeError: Cannot read property 'req' of undefined #8

Closed j0lvera closed 5 years ago

j0lvera commented 5 years ago

If I try to use it in the browser I get the error because in the browser ctx is undefined and we need to check for that before checking if ctx.req is defined.

nfriedly commented 5 years ago

I think you might be doing something wrong, the context parameter should be passed in on both client and server, see https://nextjs.org/docs/#fetching-data-and-component-lifecycle

j0lvera commented 5 years ago

🤦🏾‍♂️ you're right, I was doing it wrong. My apologies. Thanks for the quick response!