Files
faunosteo/packages/supabase/src/client.ts
T

32 lines
913 B
TypeScript

import { createClient, type SupabaseClient } from '@supabase/supabase-js'
import type { Database } from './database.types'
/** Typed Supabase client for the Faunosteo database. */
export type FaunosteoClient = SupabaseClient<Database>
/**
* Public connection settings. The anon (publishable) key is safe to ship to
* the browser: every table is behind RLS. The service-role key never is.
*/
export interface SupabaseConnection {
url: string
anonKey: string
}
/**
* Browser client: session persisted in localStorage, tokens refreshed in the
* background, PKCE for OAuth and magic-link redirects.
*/
export function createBrowserClient(
connection: SupabaseConnection,
): FaunosteoClient {
return createClient<Database>(connection.url, connection.anonKey, {
auth: {
persistSession: true,
autoRefreshToken: true,
detectSessionInUrl: true,
flowType: 'pkce',
},
})
}