feat(billing): implement robust in-app subscription cancellation & fix CI/CD socket port typo

This commit is contained in:
Antigravity
2026-05-28 20:50:11 +00:00
parent f5608372dc
commit 457c6fa626
22 changed files with 656 additions and 460 deletions

View File

@@ -0,0 +1,30 @@
import { NextRequest, NextResponse } from 'next/server';
import { auth } from '@/auth';
import { cancelSubscription } from '@/lib/billing/cancel-subscription';
export const dynamic = 'force-dynamic';
export async function POST(req: NextRequest) {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const userId = session.user.id;
try {
const result = await cancelSubscription(userId);
if (!result.success) {
const isNotFound = result.error === 'No active subscription found';
return NextResponse.json(
{ error: result.error },
{ status: isNotFound ? 404 : 400 }
);
}
return NextResponse.json({ success: true });
} catch (error) {
console.error('[billing/cancel] Route handler crash:', error);
return NextResponse.json({ error: 'Failed to cancel subscription' }, { status: 500 });
}
}