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 <noreply@anthropic.com>
This commit is contained in:
Andymick
2026-07-18 06:53:56 +01:00
co-authored by Claude Haiku 4.5
parent 4dfbffc9ce
commit 7434b68a79
2 changed files with 5 additions and 0 deletions
+2
View File
@@ -128,6 +128,7 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag
// Mark that we're checking out so LogoutOnUnload doesn't clear cart // Mark that we're checking out so LogoutOnUnload doesn't clear cart
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
sessionStorage.setItem('isCheckingOut', 'true'); sessionStorage.setItem('isCheckingOut', 'true');
console.log('Checkout button clicked: isCheckingOut flag set');
} }
const res = await fetch('/api/checkout', { 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.'); throw new Error(data.error ?? 'Something went wrong starting checkout.');
} }
console.log('Redirecting to Stripe:', data.url);
window.location.href = data.url; window.location.href = data.url;
} catch (err) { } catch (err) {
const errorMsg = err instanceof Error ? err.message : 'Something went wrong.'; const errorMsg = err instanceof Error ? err.message : 'Something went wrong.';
+3
View File
@@ -16,11 +16,14 @@ export default function LogoutOnUnload() {
// Don't logout if we're in the middle of checkout (navigating to Stripe) // 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 // The checkout component sets this flag before making the API call
const isCheckingOut = typeof window !== 'undefined' && sessionStorage.getItem('isCheckingOut'); const isCheckingOut = typeof window !== 'undefined' && sessionStorage.getItem('isCheckingOut');
console.log('LogoutOnUnload handleUnload called, isCheckingOut flag:', isCheckingOut);
if (isCheckingOut) { if (isCheckingOut) {
console.log('Skipping logout because isCheckingOut is set');
return; return;
} }
// Clear cart on logout // Clear cart on logout
console.log('Clearing cart and logging out');
clearCart(); clearCart();
// Use sendBeacon to reliably send logout even when page is closing // Use sendBeacon to reliably send logout even when page is closing
// This doesn't wait for a response, which is fine for logout // This doesn't wait for a response, which is fine for logout