I have a headless shopify site I am building with the storefront api and when a cart is created a cartId
is returned.
I am using nuxt3 with the useCookie
composable
const cartId = useCookie('cartId')
So for my sites domain https://my-shop.com
which is on netlify, there is a cookie cartId
with a value 123
.
I can use a netlify edge function, or a nuxt server api route to try to get the cookie, but I believe it is trying to get the cookie off of the incoming request. The two blocks below were my attempt to clear the site’s cartId
cookie post checkout.
With nuxt
export default defineEventHandler(e => {
deleteCookie(e, 'cartId')
})
or with netlify edge function
export default async (req, context) => {
context.cookies.delete('cartId')
}
When a user creates a checkout, since the site is headless they get directed to a subdomain, https://checkout.my-shop.com
which is the shopify hosted checkout. I have a shopify webhook setup that hits the endpoint for the netlify edge function, or nuxt server route after the checkout is complete.
I need to clear this cookie since it is associated with a cart, and that cart is invalid after checkout.