From a3682e6c2e6510728e332e027e612eb175f4ce40 Mon Sep 17 00:00:00 2001 From: joel Date: Wed, 4 Sep 2024 19:29:33 +0800 Subject: [PATCH] fix: add support for storage key --- src/createBrowserClient.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/createBrowserClient.ts b/src/createBrowserClient.ts index 0f34f93..a7c3337 100644 --- a/src/createBrowserClient.ts +++ b/src/createBrowserClient.ts @@ -52,7 +52,7 @@ export function createBrowserClient< : string & keyof Database, Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] - : any, + : any >( supabaseUrl: string, supabaseKey: string, @@ -61,7 +61,7 @@ export function createBrowserClient< cookieOptions?: CookieOptionsWithName; cookieEncoding?: "raw" | "base64url"; isSingleton?: boolean; - }, + } ): SupabaseClient; /** @@ -76,7 +76,7 @@ export function createBrowserClient< : string & keyof Database, Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] - : any, + : any >( supabaseUrl: string, supabaseKey: string, @@ -85,7 +85,7 @@ export function createBrowserClient< cookieOptions?: CookieOptionsWithName; cookieEncoding?: "raw" | "base64url"; isSingleton?: boolean; - }, + } ): SupabaseClient; export function createBrowserClient< @@ -95,7 +95,7 @@ export function createBrowserClient< : string & keyof Database, Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] - : any, + : any >( supabaseUrl: string, supabaseKey: string, @@ -104,7 +104,7 @@ export function createBrowserClient< cookieOptions?: CookieOptionsWithName; cookieEncoding?: "raw" | "base64url"; isSingleton?: boolean; - }, + } ): SupabaseClient { // singleton client is created only if isSingleton is set to true, or if isSingleton is not defined and we detect a browser const shouldUseSingleton = @@ -117,7 +117,7 @@ export function createBrowserClient< if (!supabaseUrl || !supabaseKey) { throw new Error( - `@supabase/ssr: Your project's URL and API key are required to create a Supabase client!\n\nCheck your Supabase project's API settings to find these values\n\nhttps://supabase.com/dashboard/project/_/settings/api`, + `@supabase/ssr: Your project's URL and API key are required to create a Supabase client!\n\nCheck your Supabase project's API settings to find these values\n\nhttps://supabase.com/dashboard/project/_/settings/api` ); } @@ -126,9 +126,11 @@ export function createBrowserClient< ...options, cookieEncoding: options?.cookieEncoding ?? "base64url", }, - false, + false ); + const storageKey = options?.auth?.storageKey || options?.cookieOptions?.name; + const client = createClient( supabaseUrl, supabaseKey, @@ -143,16 +145,14 @@ export function createBrowserClient< }, auth: { ...options?.auth, - ...(options?.cookieOptions?.name - ? { storageKey: options.cookieOptions.name } - : null), + ...(storageKey ? { storageKey } : null), flowType: "pkce", autoRefreshToken: isBrowser(), detectSessionInUrl: isBrowser(), persistSession: true, storage, }, - }, + } ); if (shouldUseSingleton) {