diff --git a/app/api/webhooks/stripe/route.ts b/app/api/webhooks/stripe/route.ts index a421f81..a6f5578 100644 --- a/app/api/webhooks/stripe/route.ts +++ b/app/api/webhooks/stripe/route.ts @@ -41,6 +41,11 @@ export async function POST(request: Request) { const subscription = await stripe.subscriptions.retrieve( session.subscription as string ); + + if (!subscription.current_period_end) { + return new Response("Invalid subscription data", { status: 400 }); + } + const updatedData = { stripeSubscriptionId: subscription.id, stripeCustomerId: subscription.customer as string, @@ -82,6 +87,10 @@ export async function POST(request: Request) { session.subscription as string ); + if (!subscription.current_period_end) { + return new Response("Invalid subscription data", { status: 400 }); + } + // Update the price id and set the new period end. await db .update(subscriptions)