james emanon
james emanon

Reputation: 11837

Best way to handle a previous session with NextJS for ecommerce

Lets say I have an ecommerce site.

Most, if not all of the APIS live on another server.

  1. A user puts a couple things in cart
  2. signs in, or doesn't
  3. Leaves site

come back at a later time.

  1. Session fires from cookie, prepopulates cart

What I am confused about is how this can be done sitewide and work with prerendering etc.. I AM NEW TO NEXTJS.

Write now, on my current site, I am just calling the session api. presaturating the redux and then display the page. Standard stuff. curious how this would work with Next and prerendeirng/static generations etc...

Upvotes: 0

Views: 112

Answers (1)

A Webb
A Webb

Reputation: 711

Static generations are only available for data that exists at build-time which in this case would exist on request time - therefore you can only achieve pre-rendering via SSR.

From the official documentation:

“You should use getServerSideProps only if you need to pre-render a page whose data must be fetched at request time.”

https://nextjs.org/learn/basics/data-fetching/request-time

Upvotes: 1

Related Questions