From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Persist session cart

Persist session cart

Okay, so we have our cart implemented, we can add products to the cart, but we have an issue here, and that is if we add them as a guest and then we sign in, the cart actually isn't going to be there anymore. The items aren't going to be there anymore, and I'll give you an example. So I'm not logged in, I'm going to add this to my cart, I can see it here, and then if I go and I sign in and go to my cart, it's gone, right? There's nothing there. So what we have to do is basically check for when we sign in, we want to check to see if the user has a guest card or with the session or should call it a session card and if they do then we want to make it the user card. So let's sign out and what I'm going to have you do is go to your Prisma Studio and go to your cart table and reload it and then just delete any cart that's there, right? Just wipe it out just so we can kind of start fresh and then log out and then open up your DevTools and just delete any, just delete all the cookies, okay?…

Contents