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:
parent
d3e3625375
commit
b5c399257f
1 changed files with 5 additions and 1 deletions
|
|
@ -26,10 +26,14 @@ export async function POST(request: Request) {
|
|||
const baseUrl =
|
||||
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 {
|
||||
const result = await createCheckoutSession({
|
||||
userId: session.user.id,
|
||||
customerEmail: session.user.email ?? undefined,
|
||||
customerEmail,
|
||||
appSlug,
|
||||
baseUrl,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue