-
Notifications
You must be signed in to change notification settings - Fork 232
/
createClient.ts
44 lines (41 loc) · 1.14 KB
/
createClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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,
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
? Database[SchemaName]
: any
>(
supabaseUrl: string,
supabaseKey: string,
options: SupabaseClientOptionsWithoutAuth<SchemaName> & {
auth: {
storage: StorageAdapter;
storageKey?: string;
};
}
) {
const bowser = isBrowser();
return createClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, {
...options,
auth: {
flowType: 'pkce',
autoRefreshToken: bowser,
detectSessionInUrl: bowser,
persistSession: true,
storage: options.auth.storage,
// fix this in supabase-js
...(options.auth?.storageKey
? {
storageKey: options.auth.storageKey
}
: {})
}
});
}