Add isCheckingOut flag to guest checkout flow
Guest checkout handler was missing the sessionStorage flag that prevents LogoutOnUnload from clearing cart during Stripe redirect. Adds flag before API call and removes on error. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
eda518d1be
commit
570be6430c
@@ -55,6 +55,9 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag
|
|||||||
setCheckingOut(true);
|
setCheckingOut(true);
|
||||||
setCheckoutError(null);
|
setCheckoutError(null);
|
||||||
try {
|
try {
|
||||||
|
// Mark that we're checking out so LogoutOnUnload doesn't clear cart
|
||||||
|
sessionStorage.setItem('isCheckingOut', 'true');
|
||||||
|
|
||||||
const res = await fetch('/api/checkout', {
|
const res = await fetch('/api/checkout', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -70,6 +73,7 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag
|
|||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (!res.ok || !data.url) {
|
if (!res.ok || !data.url) {
|
||||||
|
sessionStorage.removeItem('isCheckingOut');
|
||||||
throw new Error(data.error ?? 'Something went wrong starting checkout.');
|
throw new Error(data.error ?? 'Something went wrong starting checkout.');
|
||||||
}
|
}
|
||||||
window.location.href = data.url;
|
window.location.href = data.url;
|
||||||
|
|||||||
Reference in New Issue
Block a user