diff --git a/src/runtime/server/services/serverSupabaseClient.ts b/src/runtime/server/services/serverSupabaseClient.ts index d0af23df..ddaca927 100644 --- a/src/runtime/server/services/serverSupabaseClient.ts +++ b/src/runtime/server/services/serverSupabaseClient.ts @@ -2,24 +2,25 @@ import { createClient, SupabaseClient } from '@supabase/supabase-js' import { getCookie } from 'h3' import type { H3Event } from 'h3' import { useRuntimeConfig } from '#imports' +import { defu } from 'defu' export const serverSupabaseClient = async (event: H3Event): Promise> => { // get settings from runtime config const { - supabase: { url, key, cookieName }, + supabase: { url, key, cookieName, clientOptions }, } = useRuntimeConfig().public let supabaseClient = event.context._supabaseClient as SupabaseClient // No need to recreate client if exists in request context if (!supabaseClient) { - supabaseClient = createClient(url, key, { - auth: { - detectSessionInUrl: false, - persistSession: false, - autoRefreshToken: false, - }, - }) + // Merge defaults with user config + const options = defu({ auth: { + detectSessionInUrl: false, + persistSession: false, + autoRefreshToken: false + } }, clientOptions) + supabaseClient = createClient(url, key, options) event.context._supabaseClient = supabaseClient }