Skip to content

Commit cdcae3b

Browse files
committed
fix: Make Stripe optional during build, check at runtime
1 parent 8b5d360 commit cdcae3b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

app/api/stripe/checkout/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ const checkoutSchema = z.object({
1616

1717
export async function POST(request: NextRequest) {
1818
try {
19+
if (!process.env.STRIPE_SECRET_KEY) {
20+
return NextResponse.json(
21+
{ error: 'Stripe not configured' },
22+
{ status: 500 }
23+
)
24+
}
25+
1926
const session = await getServerSession(authOptions)
2027

2128
if (!session?.user) {

app/api/stripe/portal/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import prisma from '@/app/lib/db'
1111

1212
export async function POST(request: NextRequest) {
1313
try {
14+
if (!process.env.STRIPE_SECRET_KEY) {
15+
return NextResponse.json(
16+
{ error: 'Stripe not configured' },
17+
{ status: 500 }
18+
)
19+
}
20+
1421
const session = await getServerSession(authOptions)
1522

1623
if (!session?.user) {

app/lib/stripe.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
import Stripe from 'stripe'
66

7-
if (!process.env.STRIPE_SECRET_KEY) {
8-
throw new Error('STRIPE_SECRET_KEY is required')
9-
}
7+
// Allow build to succeed without Stripe key (will be set in production env)
8+
const stripeSecretKey = process.env.STRIPE_SECRET_KEY || 'sk_test_placeholder_for_build'
109

11-
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
10+
export const stripe = new Stripe(stripeSecretKey, {
1211
apiVersion: '2025-12-15.clover',
1312
typescript: true,
1413
})

0 commit comments

Comments
 (0)