Skip to content

fix: construct supabaseAdmin lazily on first access - #124

Merged
mandarini merged 1 commit into
mainfrom
fix/lazy-admin-client
Aug 25, 2026
Merged

fix: construct supabaseAdmin lazily on first access#124
mandarini merged 1 commit into
mainfrom
fix/lazy-admin-client

Conversation

@mandarini

@mandarinimandarini commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

withSupabase folded the admin client entry eagerly, so createAdminClient ran on every request and a project with no secret key configured got a 500 on every request, even when the handler never touched ctx.supabaseAdmin. The entry now contributes a lazy, per-request memoized Proxy (new lazyClient helper in src/core/lazy-client.ts): construction happens on the first property access, so handlers that never use the admin client need no secret key, and a missing key surfaces as an EnvError at the point of use instead of a blanket 500. Proxy methods are bound to the real instance so supabase-js internals (private fields, prototype getters) keep working. The non-admin client entry, the createAdminClient public API, and the client-phase error mapping are unchanged; tests cover the new contract and docs reflect when the secret key is required.

@pkg-pr-new

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@supabase/server@124

commit: 5db9d3f

@mandarinimandarini self-assigned this Aug 25, 2026
@mandarini
mandarini marked this pull request as ready for review August 25, 2026 12:21
@mandarini
mandarini requested review from a team as code ownersAugust 25, 2026 12:21
@mandarini
mandarini merged commit fbb652f into mainAug 25, 2026
9 checks passed
@mandarini
mandarini deleted the fix/lazy-admin-client branch August 25, 2026 12:50
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@mandarini@spydon