Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lib/resend.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Resend } from 'resend'
import { generateQRCodeBuffer } from './qr-code'

const resend = new Resend(process.env.RESEND_API_KEY)
function getResend() {
if (!process.env.RESEND_API_KEY) {
throw new Error('RESEND_API_KEY is not configured')
}
return new Resend(process.env.RESEND_API_KEY)
}

export interface TicketEmailData {
attendeeName: string
Expand All @@ -15,6 +20,7 @@ export interface TicketEmailData {
}

export async function sendTicketEmail(data: TicketEmailData) {
const resend = getResend()
try {
// Generate QR code image
const qrCodeBuffer = await generateQRCodeBuffer(data.qrCodeData)
Expand Down
60 changes: 48 additions & 12 deletions src/lib/supabase.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
import { createClient } from '@supabase/supabase-js'
import { Database } from './database.types'

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY!

// Client for client-side operations
export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey)

// Admin client for server-side operations with service role key
export const supabaseAdmin = createClient<Database>(supabaseUrl, supabaseServiceKey, {
auth: {
autoRefreshToken: false,
persistSession: false
// Lazy-load client for client-side operations
let supabaseInstance: ReturnType<typeof createClient<Database>> | null = null
export function getSupabase() {
if (!supabaseInstance) {
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY

if (!supabaseUrl || !supabaseAnonKey) {
throw new Error('Supabase URL and Anon Key are required')
}

supabaseInstance = createClient<Database>(supabaseUrl, supabaseAnonKey)
}
return supabaseInstance
}

// For backwards compatibility
export const supabase = new Proxy({} as ReturnType<typeof createClient<Database>>, {
get: (target, prop) => {
return getSupabase()[prop as keyof ReturnType<typeof createClient<Database>>]
}
})

// Lazy-load admin client for server-side operations with service role key
let supabaseAdminInstance: ReturnType<typeof createClient<Database>> | null = null
export function getSupabaseAdmin() {
if (!supabaseAdminInstance) {
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY

if (!supabaseUrl || !supabaseServiceKey) {
throw new Error('Supabase URL and Service Role Key are required')
}

supabaseAdminInstance = createClient<Database>(supabaseUrl, supabaseServiceKey, {
auth: {
autoRefreshToken: false,
persistSession: false
}
})
}
return supabaseAdminInstance
}

// For backwards compatibility
export const supabaseAdmin = new Proxy({} as ReturnType<typeof createClient<Database>>, {
get: (target, prop) => {
return getSupabaseAdmin()[prop as keyof ReturnType<typeof createClient<Database>>]
}
})

Expand Down
Loading