Fix cart clearing during Stripe checkout redirect
Use sessionStorage flag to prevent LogoutOnUnload from clearing cart and logging out when navigating to Stripe checkout. Changes: - Checkout button sets 'isCheckingOut' flag in sessionStorage before API call - LogoutOnUnload checks this flag and skips logout if checkout in progress - Flag is removed if API returns an error - Flag persists during navigation to Stripe URL This ensures cart and login persist through Stripe payment flow. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
017b68f17b
commit
eda518d1be
@@ -117,6 +117,9 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag
|
||||
setCheckingOut(true);
|
||||
setCheckoutError(null);
|
||||
try {
|
||||
// Mark that we're checking out so LogoutOnUnload doesn't clear cart
|
||||
sessionStorage.setItem('isCheckingOut', 'true');
|
||||
|
||||
const res = await fetch('/api/checkout', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -125,6 +128,7 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag
|
||||
const data = await res.json();
|
||||
console.log('Checkout response:', { status: res.status, ok: res.ok, data });
|
||||
if (!res.ok || !data.url) {
|
||||
sessionStorage.removeItem('isCheckingOut');
|
||||
throw new Error(data.error ?? 'Something went wrong starting checkout.');
|
||||
}
|
||||
window.location.href = data.url;
|
||||
|
||||
Reference in New Issue
Block a user