Skip to content

Commit

Permalink
fix: add support for storage key
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Sep 4, 2024
1 parent 549fe62 commit a3682e6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/createBrowserClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -61,7 +61,7 @@ export function createBrowserClient<
cookieOptions?: CookieOptionsWithName;
cookieEncoding?: "raw" | "base64url";
isSingleton?: boolean;
},
}
): SupabaseClient<Database, SchemaName, Schema>;

/**
Expand All @@ -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,
Expand All @@ -85,7 +85,7 @@ export function createBrowserClient<
cookieOptions?: CookieOptionsWithName;
cookieEncoding?: "raw" | "base64url";
isSingleton?: boolean;
},
}
): SupabaseClient<Database, SchemaName, Schema>;

export function createBrowserClient<
Expand All @@ -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,
Expand All @@ -104,7 +104,7 @@ export function createBrowserClient<
cookieOptions?: CookieOptionsWithName;
cookieEncoding?: "raw" | "base64url";
isSingleton?: boolean;
},
}
): SupabaseClient<Database, SchemaName, Schema> {
// singleton client is created only if isSingleton is set to true, or if isSingleton is not defined and we detect a browser
const shouldUseSingleton =
Expand All @@ -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`
);
}

Expand All @@ -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<Database, SchemaName, Schema>(
supabaseUrl,
supabaseKey,
Expand All @@ -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) {
Expand Down

0 comments on commit a3682e6

Please sign in to comment.