-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat!: add supabaseOptions and refactor client creation to options objects
#19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kallebysantos
merged 2 commits into
main
from
tomas/func-529-add-support-of-for-supabase-client-options
Mar 26, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,18 +5,15 @@ import { | |
| MissingDefaultSecretKeyError, | ||
| MissingSecretKeyError, | ||
| } from '../errors.js' | ||
| import type { SupabaseEnv } from '../types.js' | ||
| import type { CreateAdminClientOptions } from '../types.js' | ||
| import { resolveEnv } from './resolve-env.js' | ||
|
|
||
| /** | ||
| * Creates an admin Supabase client that bypasses Row-Level Security. | ||
| * | ||
| * Uses a secret key for authentication, giving full access to all data. | ||
| * Session persistence is disabled (stateless, one client per request). | ||
| * Stateless — one client per request. | ||
| * | ||
| * @param env - Optional environment overrides (passed through to {@link resolveEnv}). | ||
| * @param keyName - Name of the secret key to use. Falls back to `"default"`, then first available. | ||
| * @returns A configured {@link SupabaseClient} with admin (service-role) privileges. | ||
| * @throws {@link EnvError} If `SUPABASE_URL` is missing or the specified secret key is not found. | ||
| * | ||
| * @example | ||
|
|
@@ -26,12 +23,14 @@ import { resolveEnv } from './resolve-env.js' | |
| * ``` | ||
| */ | ||
| export function createAdminClient<Database = unknown>( | ||
| env?: Partial<SupabaseEnv>, | ||
| keyName?: string | null, | ||
| options?: CreateAdminClientOptions, | ||
| ): SupabaseClient<Database> { | ||
| const { data: resolved, error } = resolveEnv(env) | ||
| const { data: resolved, error } = resolveEnv(options?.env) | ||
| if (error) throw error | ||
|
|
||
| const keyName = options?.auth?.keyName | ||
| const supabaseOptions = options?.supabaseOptions | ||
|
|
||
| const name = keyName ?? 'default' | ||
| const keys = resolved.secretKeys | ||
| const secretKey = | ||
|
|
@@ -42,11 +41,25 @@ export function createAdminClient<Database = unknown>( | |
| : Errors[MissingSecretKeyError](name) | ||
| } | ||
|
|
||
| return createClient(resolved.url, secretKey, { | ||
| // Sanitize auth headers — only the service-role key controls Authorization and apikey. | ||
| const safeHeaders = { ...supabaseOptions?.global?.headers } | ||
| delete safeHeaders.Authorization | ||
| delete safeHeaders.apikey | ||
|
|
||
| // supabaseOptions uses `string` for schema; createClient<Database> expects a narrower type. | ||
| return createClient<Database>(resolved.url, secretKey, { | ||
| ...supabaseOptions, | ||
| // Stripped — token injection is managed via the service-role key. | ||
| accessToken: undefined, | ||
| global: { | ||
| ...supabaseOptions?.global, | ||
|
tomaspozo marked this conversation as resolved.
|
||
| headers: safeHeaders, | ||
| }, | ||
| auth: { | ||
| ...supabaseOptions?.auth, | ||
| persistSession: false, | ||
| autoRefreshToken: false, | ||
| detectSessionInUrl: false, | ||
| }, | ||
| }) | ||
| } as Parameters<typeof createClient<Database>>[2]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this ensures TS sync with database main type with the scoped selected schema 🤔
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: It doesn't sync types |
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.