checkout: omit customerEmail when user has guest-style email

Stripe rejects emails like 'guest-1779719735974' with 400 email_invalid.
Falling back to no email lets Stripe collect it on the checkout page itself,
which is the standard flow for unauthenticated upgrades.
This commit is contained in:
dmitry.galkin 2026-05-25 18:36:12 +04:00
parent d3e3625375
commit b5c399257f

View file

@ -26,10 +26,14 @@ export async function POST(request: Request) {
const baseUrl = const baseUrl =
process.env.NEXT_PUBLIC_BASE_URL ?? new URL(request.url).origin; process.env.NEXT_PUBLIC_BASE_URL ?? new URL(request.url).origin;
const rawEmail = session.user.email ?? "";
const looksLikeEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(rawEmail);
const customerEmail = looksLikeEmail ? rawEmail : undefined;
try { try {
const result = await createCheckoutSession({ const result = await createCheckoutSession({
userId: session.user.id, userId: session.user.id,
customerEmail: session.user.email ?? undefined, customerEmail,
appSlug, appSlug,
baseUrl, baseUrl,
}); });