fix: improve claim plan flow

This commit is contained in:
Mythie
2023-10-25 22:29:51 +11:00
parent a975509923
commit 717ca8cdb2
11 changed files with 214 additions and 277 deletions

View File

@ -32,10 +32,21 @@ export default async function ClaimedPlanPage({ searchParams = {} }: ClaimedPlan
}
const session = await stripe.checkout.sessions.retrieve(sessionId);
const customerId = typeof session.customer === 'string' ? session.customer : session.customer?.id;
if (!customerId) {
redirect('/');
}
const customer = await stripe.customers.retrieve(customerId);
if (!customer || customer.deleted) {
redirect('/');
}
const user = await prisma.user.findFirst({
where: {
id: Number(session.client_reference_id),
id: Number(customer.metadata.userId),
},
});