27 lines
856 B
TypeScript
27 lines
856 B
TypeScript
import { createClient } from '@supabase/supabase-js'
|
|
|
|
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
|
|
const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY
|
|
|
|
if (!supabaseUrl || !supabaseServiceRoleKey) {
|
|
throw new Error(
|
|
'Missing Supabase environment variables. Add NEXT_PUBLIC_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY to your .env.local file.',
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Create a Supabase client for server-side use with service role key
|
|
* This bypasses RLS and allows server actions to query the database directly
|
|
* Authentication is handled by Better Auth, permissions enforced by filtering on user_id
|
|
*/
|
|
export async function createServerSupabaseClient() {
|
|
const client = createClient(supabaseUrl, supabaseServiceRoleKey, {
|
|
auth: {
|
|
persistSession: false,
|
|
autoRefreshToken: false,
|
|
},
|
|
})
|
|
|
|
return client
|
|
}
|