mirror of
https://github.com/marcogll/AnchorOS.git
synced 2026-03-15 17:24:30 +00:00
fix: Improve API initialization with lazy Supabase client and validation
- Move Supabase/Stripe initialization inside GET/POST handlers for lazy loading - Add validation for missing environment variables in runtime - Improve error handling in payment intent creation - Clean up next.config.js environment variable configuration This fixes potential build-time failures when environment variables are not available during static generation.
This commit is contained in:
@@ -2,8 +2,6 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import Stripe from 'stripe'
|
||||
import { supabaseAdmin } from '@/lib/supabase/admin'
|
||||
|
||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
|
||||
|
||||
/**
|
||||
* @description Creates a Stripe payment intent for booking deposit (50% of service price, max $200)
|
||||
* @param {NextRequest} request - Request containing booking details
|
||||
@@ -11,6 +9,14 @@ const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
|
||||
*/
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const stripeSecretKey = process.env.STRIPE_SECRET_KEY
|
||||
|
||||
if (!stripeSecretKey) {
|
||||
return NextResponse.json({ error: 'Stripe not configured' }, { status: 500 })
|
||||
}
|
||||
|
||||
const stripe = new Stripe(stripeSecretKey)
|
||||
|
||||
const {
|
||||
customer_email,
|
||||
customer_phone,
|
||||
|
||||
Reference in New Issue
Block a user