From 0b5c23bf5d06cdc67f6dc32834e956df4625b299 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Tue, 23 May 2023 13:52:12 +0000 Subject: [PATCH] Fix: missing type from SvelteKit and remix package --- packages/remix/src/createSupabaseClient.ts | 19 +++++++++++++------ packages/shared/src/createClient.ts | 8 ++++++-- packages/sveltekit/src/supabaseLoadClient.ts | 12 ++++++++---- .../sveltekit/src/supabaseServerClient.ts | 11 ++++++++--- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/packages/remix/src/createSupabaseClient.ts b/packages/remix/src/createSupabaseClient.ts index f6c150a4..41eb8c02 100644 --- a/packages/remix/src/createSupabaseClient.ts +++ b/packages/remix/src/createSupabaseClient.ts @@ -9,6 +9,7 @@ import { SupabaseClientOptionsWithoutAuth } from '@supabase/auth-helpers-shared'; import { SupabaseClient } from '@supabase/supabase-js'; +import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types'; /** * ## Authenticated Supabase client @@ -90,7 +91,10 @@ export function createBrowserClient< Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' - : string & keyof Database + : string & keyof Database, + Schema extends GenericSchema = Database[SchemaName] extends GenericSchema + ? Database[SchemaName] + : any >( supabaseUrl: string, supabaseKey: string, @@ -101,14 +105,14 @@ export function createBrowserClient< options?: SupabaseClientOptionsWithoutAuth; cookieOptions?: CookieOptionsWithName; } = {} -): SupabaseClient { +): SupabaseClient { if (!supabaseUrl || !supabaseKey) { throw new Error( 'supabaseUrl and supabaseKey are required to create a Supabase client! Find these under `Settings` > `API` in your Supabase dashboard.' ); } - return createSupabaseClient(supabaseUrl, supabaseKey, { + return createSupabaseClient(supabaseUrl, supabaseKey, { ...options, global: { ...options?.global, @@ -159,7 +163,10 @@ export function createServerClient< Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' - : string & keyof Database + : string & keyof Database, + Schema extends GenericSchema = Database[SchemaName] extends GenericSchema + ? Database[SchemaName] + : any >( supabaseUrl: string, supabaseKey: string, @@ -174,7 +181,7 @@ export function createServerClient< options?: SupabaseClientOptionsWithoutAuth; cookieOptions?: CookieOptionsWithName; } -): SupabaseClient { +): SupabaseClient { if (!supabaseUrl || !supabaseKey) { throw new Error( 'supabaseUrl and supabaseKey are required to create a Supabase client! Find these under `Settings` > `API` in your Supabase dashboard.' @@ -187,7 +194,7 @@ export function createServerClient< ); } - return createSupabaseClient(supabaseUrl, supabaseKey, { + return createSupabaseClient(supabaseUrl, supabaseKey, { ...options, global: { ...options?.global, diff --git a/packages/shared/src/createClient.ts b/packages/shared/src/createClient.ts index f44ed2a0..3177b154 100644 --- a/packages/shared/src/createClient.ts +++ b/packages/shared/src/createClient.ts @@ -2,12 +2,16 @@ import { createClient } from '@supabase/supabase-js'; import { SupabaseClientOptionsWithoutAuth } from './types'; import { isBrowser } from './utils'; import { StorageAdapter } from './cookieAuthStorageAdapter'; +import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types'; export function createSupabaseClient< Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' - : string & keyof Database + : string & keyof Database, + Schema extends GenericSchema = Database[SchemaName] extends GenericSchema + ? Database[SchemaName] + : any >( supabaseUrl: string, supabaseKey: string, @@ -20,7 +24,7 @@ export function createSupabaseClient< ) { const bowser = isBrowser(); - return createClient(supabaseUrl, supabaseKey, { + return createClient(supabaseUrl, supabaseKey, { ...options, auth: { flowType: 'pkce', diff --git a/packages/sveltekit/src/supabaseLoadClient.ts b/packages/sveltekit/src/supabaseLoadClient.ts index 801db79c..22abf154 100644 --- a/packages/sveltekit/src/supabaseLoadClient.ts +++ b/packages/sveltekit/src/supabaseLoadClient.ts @@ -7,6 +7,7 @@ import { import { Session, SupabaseClient } from '@supabase/supabase-js'; import { LoadEvent } from '@sveltejs/kit'; import { SvelteKitLoadAuthStorageAdapter } from './loadStorageAdapter'; +import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types'; let cachedBrowserClient: SupabaseClient | undefined; @@ -52,7 +53,10 @@ export function createSupabaseLoadClient< Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' - : string & keyof Database + : string & keyof Database, + Schema extends GenericSchema = Database[SchemaName] extends GenericSchema + ? Database[SchemaName] + : any >({ supabaseUrl, supabaseKey, @@ -73,13 +77,13 @@ export function createSupabaseLoadClient< serverSession: Session | null; options?: SupabaseClientOptionsWithoutAuth; cookieOptions?: CookieOptionsWithName; -}): SupabaseClient { +}): SupabaseClient { const browser = isBrowser(); if (browser && cachedBrowserClient) { - return cachedBrowserClient as SupabaseClient; + return cachedBrowserClient as SupabaseClient; } - const client = createSupabaseClient(supabaseUrl, supabaseKey, { + const client = createSupabaseClient(supabaseUrl, supabaseKey, { ...options, global: { fetch: event.fetch, diff --git a/packages/sveltekit/src/supabaseServerClient.ts b/packages/sveltekit/src/supabaseServerClient.ts index 62887ab9..b5d6874a 100644 --- a/packages/sveltekit/src/supabaseServerClient.ts +++ b/packages/sveltekit/src/supabaseServerClient.ts @@ -5,6 +5,8 @@ import { } from '@supabase/auth-helpers-shared'; import { RequestEvent } from '@sveltejs/kit'; import { SvelteKitServerAuthStorageAdapter } from './serverStorageAdapter'; +import { GenericSchema } from '@supabase/supabase-js/dist/module/lib/types'; +import { SupabaseClient } from '@supabase/supabase-js'; /** * ## Authenticated Supabase client @@ -61,7 +63,10 @@ export function createSupabaseServerClient< Database = any, SchemaName extends string & keyof Database = 'public' extends keyof Database ? 'public' - : string & keyof Database + : string & keyof Database, + Schema extends GenericSchema = Database[SchemaName] extends GenericSchema + ? Database[SchemaName] + : any >({ supabaseUrl, supabaseKey, @@ -76,8 +81,8 @@ export function createSupabaseServerClient< options?: SupabaseClientOptionsWithoutAuth; cookieOptions?: CookieOptionsWithName; expiryMargin?: number; -}) { - const client = createSupabaseClient(supabaseUrl, supabaseKey, { +}): SupabaseClient { + const client = createSupabaseClient(supabaseUrl, supabaseKey, { ...options, global: { ...options?.global,