From ee5210eae789037e3dfbfe2f9586f82b3ee670dc Mon Sep 17 00:00:00 2001 From: Ian Jones Date: Tue, 26 Sep 2023 16:42:44 +0100 Subject: [PATCH] Use clientOptions fix#275 --- .../server/services/serverSupabaseClient.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 }