38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { createSupabaseServerClient } from '@/lib/supabase/server';
|
|
|
|
export const runtime = 'nodejs';
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export async function POST() {
|
|
const supabase = createSupabaseServerClient();
|
|
const {
|
|
data: { user },
|
|
} = await supabase.auth.getUser();
|
|
if (!user) {
|
|
return NextResponse.json({ error: 'unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const stub = process.env.STRIPE_STUB_URL;
|
|
if (!stub) {
|
|
return NextResponse.json(
|
|
{ error: 'STRIPE_STUB_URL not configured' },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
|
|
const res = await fetch(`${stub}/v1/checkout/sessions`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ customer_email: user.email }),
|
|
});
|
|
if (!res.ok) {
|
|
return NextResponse.json(
|
|
{ error: `stripe-stub returned ${res.status}` },
|
|
{ status: 502 },
|
|
);
|
|
}
|
|
const body = (await res.json()) as Record<string, unknown>;
|
|
return NextResponse.json(body);
|
|
}
|