feat!: add supabaseOptions and refactor client creation to options objects - #19
Conversation
FUNC-529 Add support of for supabase client options
We should allow users to customize the way the way the internal clients are initialized: and we extend the interface like this, and pass down export interface WithSupabaseConfig {
...
supabaseOptions: SupabaseClientOptions<SchemaName>
} |
377d229 to
ac099ac
Compare
…ization Allow users to pass `SupabaseClientOptions` through to the internal `createClient` calls, enabling custom schemas, fetch, and realtime config while security-critical auth settings remain force-overwritten.
ac099ac to
629168d
Compare
supabaseOptions and refactor client creation to options objects
There was a problem hiding this comment.
Pull request overview
Adds a supabaseOptions escape hatch to customize the internal Supabase client creation while refactoring createContextClient / createAdminClient to accept options objects, and wiring the options through createSupabaseContext / withSupabase.
Changes:
- Add
supabaseOptions?: SupabaseClientOptions<string>toWithSupabaseConfigand introduceClientAuth,CreateContextClientOptions, andCreateAdminClientOptionstypes. - Refactor
createContextClient/createAdminClientto accept options objects and merge forwardedsupabaseOptions. - Update and extend tests to cover the new options-object APIs and basic
supabaseOptionsplumbing.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types.ts | Adds new public config/options types and the supabaseOptions config field. |
| src/index.ts | Re-exports the newly introduced types from the main entrypoint. |
| src/create-supabase-context.ts | Threads supabaseOptions into both context and admin client creation via options objects. |
| src/create-supabase-context.test.ts | Adds a basic test for supabaseOptions plumbing through createSupabaseContext. |
| src/core/index.ts | Re-exports the new types from the ./core entrypoint. |
| src/core/create-context-client.ts | Refactors to options object and merges forwarded supabaseOptions into createClient() options. |
| src/core/create-context-client.test.ts | Updates for options-object signature and adds basic supabaseOptions tests. |
| src/core/create-admin-client.ts | Refactors to options object and merges forwarded supabaseOptions into createClient() options. |
| src/core/create-admin-client.test.ts | Updates for options-object signature and adds a basic supabaseOptions test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
User-provided supabaseOptions.global.headers could include Authorization or apikey, bypassing verified credentials. Strip both before spreading user headers into the client options.
| detectSessionInUrl: false, | ||
| }, | ||
| }) | ||
| } as Parameters<typeof createClient<Database>>[2]) |
There was a problem hiding this comment.
I believe this ensures TS sync with database main type with the scoped selected schema 🤔
There was a problem hiding this comment.
Update: It doesn't sync types
There was a problem hiding this comment.
Looks good to me!!
Just not really sure if the final Typescript will scope the selected schema, since its expects narrow types and passing down the SchemaName.
Update: Its not scoping to selected schema
Summary
supabaseOptions?: SupabaseClientOptions<string>toWithSupabaseConfig, allowing users to customize internalcreateClient()calls (e.g.,db.schema, customfetch, realtime config)persistSession,autoRefreshToken,detectSessionInUrl) and theAuthorizationheader are always force-overwritten