mirror of
https://github.com/marcogll/AnchorOS.git
synced 2026-03-15 18:24:31 +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:
@@ -14,17 +14,20 @@ import { createClient } from '@supabase/supabase-js'
|
||||
* @audit RELIABILITY: Cron job should run exactly at Monday 00:00 UTC weekly
|
||||
*/
|
||||
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
|
||||
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY
|
||||
|
||||
if (!supabaseUrl || !supabaseServiceKey) {
|
||||
throw new Error('Missing Supabase environment variables')
|
||||
}
|
||||
|
||||
const supabase = createClient(supabaseUrl, supabaseServiceKey)
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
|
||||
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY
|
||||
|
||||
if (!supabaseUrl || !supabaseServiceKey) {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Missing Supabase environment variables' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
|
||||
const supabase = createClient(supabaseUrl, supabaseServiceKey)
|
||||
|
||||
const authHeader = request.headers.get('authorization')
|
||||
|
||||
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
||||
|
||||
Reference in New Issue
Block a user