Cookies Method

Update getServerSideProps

User Context is restored within getServerSideProps through the following steps:

  1. This context is immediately parsed at the top of the getServerSideProps function.

  2. The Intelligems config is pulled from our CDN.

  3. The User Context, the Intelligems config, and all other page props are merged and returned as props.

Example Configuration

import { withIntelligemsProps, IgCookiesContext } from '@intelligems/headless/next'

export const getServerSideProps = async ({
  req,
  preview,
  locale,
  locales,
}: GetServerSidePropsContext) => {
  const igContext = IgCookiesContext.getUserContext(req)
  
  const categories = ...
  const pages = ...

    ...
    ...
    
  const finalProps = await withIntelligemsProps({
      products,
      categories,
      brands,
      pages,
    },
    igContext
  )

  return {
    props: finalProps,
  }
}