All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 12s
- Sidebar: dynamic brand-accent colors, brainstorm section restyled - AI chat general: popup panel with expand/collapse, hides when contextual AI open - AI chat contextual: tabs reordered (Actions first), X close button, height fix - Settings: all tabs restyled, 6 new color presets (sage, terracotta, iron, etc.) - Global color cleanup: emerald/orange hardcoded → brand-accent dynamic - Brainstorm page: orange → brand-accent throughout - PageEntry animation component added to key pages - Floating AI button: bg-brand-accent instead of hardcoded black - i18n: all 15 locales updated with new AI/billing keys - Billing: freemium quota tracking, BYOK, stripe subscription scaffolding - Admin: integrated into new design - AGENTS.md + CLAUDE.md project rules added
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { auth } from '@/auth';
|
|
import { stripe } from '@/lib/stripe';
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
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 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 portalSession = await stripe.billingPortal.sessions.create({
|
|
customer: subscription.stripeCustomerId,
|
|
return_url: `${origin}/settings/billing`,
|
|
});
|
|
|
|
return NextResponse.json({ url: portalSession.url });
|
|
} catch (error) {
|
|
console.error('[billing/portal]', error);
|
|
return NextResponse.json({ error: 'Failed to create portal session' }, { status: 500 });
|
|
}
|
|
}
|