Getting started
To use cookies in Next.js, we need to install 2 npm packages: cookies and cookie-cutter. cookies allows us to set the cookie from the server side while the cookie-cutter lets us access the set cookie from the client side.
npm install cookies cookie-cutter
Setting up the utils module for cookies which work both with server side and client side
Giving your app access to the server side cookies
We will use getInitialProps in our pages/_app.js file to check if the user already has a valid cookie on the server side before rendering the app. An alternative to this approach is using getServerSideProps.