From 7434b68a7992dc8c0178fe9386b6a1ccd61cfc0c Mon Sep 17 00:00:00 2001 From: Andymick Date: Sat, 18 Jul 2026 06:53:56 +0100 Subject: [PATCH] Add debug logging for checkout and LogoutOnUnload Add console logs to track: - When isCheckingOut flag is set in checkout button - When LogoutOnUnload handleUnload is called - Whether isCheckingOut flag is detected - When redirecting to Stripe URL This helps diagnose why cart is still being cleared during checkout. Co-Authored-By: Claude Haiku 4.5 --- src/app/checkout/client.tsx | 2 ++ src/components/LogoutOnUnload.tsx | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/app/checkout/client.tsx b/src/app/checkout/client.tsx index 0657ab7..f3727cb 100644 --- a/src/app/checkout/client.tsx +++ b/src/app/checkout/client.tsx @@ -128,6 +128,7 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag // Mark that we're checking out so LogoutOnUnload doesn't clear cart if (typeof window !== 'undefined') { sessionStorage.setItem('isCheckingOut', 'true'); + console.log('Checkout button clicked: isCheckingOut flag set'); } const res = await fetch('/api/checkout', { @@ -143,6 +144,7 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag } throw new Error(data.error ?? 'Something went wrong starting checkout.'); } + console.log('Redirecting to Stripe:', data.url); window.location.href = data.url; } catch (err) { const errorMsg = err instanceof Error ? err.message : 'Something went wrong.'; diff --git a/src/components/LogoutOnUnload.tsx b/src/components/LogoutOnUnload.tsx index 1abe0c1..0c0f5b9 100644 --- a/src/components/LogoutOnUnload.tsx +++ b/src/components/LogoutOnUnload.tsx @@ -16,11 +16,14 @@ export default function LogoutOnUnload() { // Don't logout if we're in the middle of checkout (navigating to Stripe) // The checkout component sets this flag before making the API call const isCheckingOut = typeof window !== 'undefined' && sessionStorage.getItem('isCheckingOut'); + console.log('LogoutOnUnload handleUnload called, isCheckingOut flag:', isCheckingOut); if (isCheckingOut) { + console.log('Skipping logout because isCheckingOut is set'); return; } // Clear cart on logout + console.log('Clearing cart and logging out'); clearCart(); // Use sendBeacon to reliably send logout even when page is closing // This doesn't wait for a response, which is fine for logout