feat(billing): implement robust in-app subscription cancellation & fix CI/CD socket port typo
This commit is contained in:
@@ -11,13 +11,21 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
const userId = session.user.id;
|
||||
|
||||
let action = 'portal';
|
||||
try {
|
||||
const body = await req.json();
|
||||
if (body?.action) action = body.action;
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
const subscription = await prisma.subscription.findUnique({ where: { userId } });
|
||||
if (!subscription?.stripeCustomerId) {
|
||||
return NextResponse.json({ error: 'No active subscription found' }, { status: 404 });
|
||||
}
|
||||
|
||||
const origin = req.headers.get('origin') ?? process.env.NEXTAUTH_URL ?? 'http://localhost:3000';
|
||||
const host = req.headers.get('x-forwarded-host') ?? req.headers.get('host') ?? 'localhost:3000';
|
||||
const proto = req.headers.get('x-forwarded-proto') ?? 'http';
|
||||
const origin = `${proto}://${host}`;
|
||||
|
||||
const portalSession = await stripe.billingPortal.sessions.create({
|
||||
customer: subscription.stripeCustomerId,
|
||||
|
||||
Reference in New Issue
Block a user