storefront-api-examples icon indicating copy to clipboard operation
storefront-api-examples copied to clipboard

How to clear localstorage/cookies (cart/checkout) on custom front-end?

Open ollebergkvist opened this issue 3 years ago • 0 comments

I just finished creating a Next.js app using the Storefront API.

However I can't see that there's a way to query the API to see if a checkout was completed, which could be used to unset localStorage/cookie used to store a user's cart items...

As the checkout flow lives on another domain this is a bit tricky, my "work-around" fix was to create an API route to unset the cookie that contains the cart info server-side, and add a redirection to the home route.

So once the user ends up on the order confirmation page, a script runs to redirect them to the defined API route on the custom frontend...

It's a bit hacky and it's not the best UX.... also there's a risk that a user will close the window before the timeout...

Did I miss something crucial in the docs? Or was this scenario simply not considered?

Thank you!

ollebergkvist avatar Nov 22 '22 22:11 ollebergkvist