diff --git a/src/app/checkout/client.tsx b/src/app/checkout/client.tsx index 3199a2e..0657ab7 100644 --- a/src/app/checkout/client.tsx +++ b/src/app/checkout/client.tsx @@ -56,7 +56,9 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag setCheckoutError(null); try { // Mark that we're checking out so LogoutOnUnload doesn't clear cart - sessionStorage.setItem('isCheckingOut', 'true'); + if (typeof window !== 'undefined') { + sessionStorage.setItem('isCheckingOut', 'true'); + } const res = await fetch('/api/checkout', { method: 'POST', @@ -73,7 +75,9 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag }); const data = await res.json(); if (!res.ok || !data.url) { - sessionStorage.removeItem('isCheckingOut'); + if (typeof window !== 'undefined') { + sessionStorage.removeItem('isCheckingOut'); + } throw new Error(data.error ?? 'Something went wrong starting checkout.'); } window.location.href = data.url; @@ -122,7 +126,9 @@ export default function CheckoutPageClient({ isLoggedIn, customer }: CheckoutPag setCheckoutError(null); try { // Mark that we're checking out so LogoutOnUnload doesn't clear cart - sessionStorage.setItem('isCheckingOut', 'true'); + if (typeof window !== 'undefined') { + sessionStorage.setItem('isCheckingOut', 'true'); + } const res = await fetch('/api/checkout', { method: 'POST', @@ -132,7 +138,9 @@ 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'); + if (typeof window !== 'undefined') { + sessionStorage.removeItem('isCheckingOut'); + } throw new Error(data.error ?? 'Something went wrong starting checkout.'); } window.location.href = data.url;