Shopify / storefront-api-examples

Example custom storefront applications built on Shopify's Storefront API
https://help.shopify.com/api/storefront-api
MIT License
1.12k stars 329 forks source link

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

Open ollebergkvist opened 1 year ago

ollebergkvist commented 1 year ago

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!