initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { NextResponse, type NextRequest } from 'next/server';
|
||||
import { createSupabaseServerClient } from '@/lib/supabase/server';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const supabase = createSupabaseServerClient();
|
||||
const {
|
||||
data: { user },
|
||||
} = await supabase.auth.getUser();
|
||||
if (!user) {
|
||||
return NextResponse.json({ error: 'unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
let session: string | null = null;
|
||||
try {
|
||||
const body = (await req.json()) as { session?: string };
|
||||
session = body.session ?? null;
|
||||
} catch {
|
||||
// ignore — session id is optional in stub
|
||||
}
|
||||
|
||||
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/webhooks/test`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
session,
|
||||
customer_email: user.email,
|
||||
user_id: user.id,
|
||||
}),
|
||||
});
|
||||
if (!res.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: `stripe-stub returned ${res.status}` },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
const body = await res.json().catch(() => ({}));
|
||||
return NextResponse.json({ ok: true, stub: body });
|
||||
}
|
||||
Reference in New Issue
Block a user