Repository navigation
fix(http): send Supabase apikey header when anonKey is configured - #6
Merged
Merged
Conversation
Supabase Kong (the gateway in front of /functions/v1/*) rejects every
request that lacks an `apikey` header, even when Authorization carries a
valid Bearer JWT. The SDK previously only emitted Authorization, so any
caller whose baseUrl pointed at a Supabase Edge Function got back a 400
with `{"message":"No API key found in request"}`.
Adds a typed `anonKey` field to ScaffaldConfig and has HttpClient emit
`apikey: <anonKey>` on every request when it's set. Public-endpoint
callers can pass anonKey alone (no Authorization) — useful for
unauthenticated routes like /v1/auth/magic-link.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
7 tasks
thinkclay
added a commit
to Scaffald/SaaS
that referenced
this pull request
Jun 11, 2026
Picks up the merged Scaffald/sdk#6 — the typed anonKey field and apikey-header emit are now on main. Co-Authored-By: Claude Opus 4.7 <[email protected]>
thinkclay
added a commit
to Scaffald/SaaS
that referenced
this pull request
Jun 11, 2026
…ikey (#341) * fix(auth): stop prod magic-link from hitting localhost and missing apikey Two distinct bugs combined to break magic-link on app.scaffald.com: 1. `EXPO_PUBLIC_SCAFFALD_API_URL=http://127.0.0.1:54321/...` in `.env` leaked into the prod web bundle. Expo loads `.env` before `.env.production`, and `.env.production` doesn't define this var, so the dev value survived. The Scaffald SDK then routed every call to localhost from users' browsers. Fixed by documenting the gotcha prominently in `.env.template` (`.env` is gitignored — devs need to update their local copy). 2. Even if the URL were right, every request hit Supabase Kong without an `apikey` header, which Kong requires on `/functions/v1/*` (it returns `400 {"message":"No API key found in request"}` regardless of Authorization). Fixed at the SDK level (see Scaffald/sdk#6 — adds typed `anonKey` field, HttpClient emits `apikey` header from it) and plumbed through `jobs-sdk-context.tsx` from `EXPO_PUBLIC_SUPABASE_ANON_KEY`. Bumps `packages/sdk` to a2bd925 (fix/http-anonkey-apikey-header branch); re-bump to the merge commit once Scaffald/sdk#6 lands. Verified against a fresh prod-mode bundle: - `127.0.0.1:54321` no longer appears in `entry-*.js`. - `auth.scaffald.com` is the only Supabase host present. - `this.config.anonKey && (v.apikey = ...)` is in the minified output. Co-Authored-By: Claude Opus 4.7 <[email protected]> * chore(sdk): bump submodule to Scaffald/sdk@11a863b Picks up the merged Scaffald/sdk#6 — the typed anonKey field and apikey-header emit are now on main. Co-Authored-By: Claude Opus 4.7 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
3 tasks done
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
anonKeyfield toScaffaldConfigand hasHttpClientemitapikey: <anonKey>on every request when set./v1/auth/magic-link) can now passanonKeyalone — noAuthorizationrequired.<project>.supabase.co/functions/v1/api) was rejected with400 {"message":"No API key found in request"}.Why this exists
Supabase's Kong gateway requires an
apikeyheader on every/functions/v1/*request, even whenAuthorizationcarries a valid Bearer JWT. The SDK only emittedAuthorization, so unauthenticated routes (magic-link) and even authenticated ones (anything proxied through Kong) failed at the gateway before the Edge Function ever ran. Discovered while debugging a prod magic-link regression on UNI-Construct.Test plan
pnpm test— 777/777 passpnpm typecheck— cleanpnpm build— clean dual CJS/ESM emit;apikeyliteral verified in built chunkBackwards compat
anonKeyis optional; existing callers that don't set it get identical behavior (noapikeyheader sent).anonKeyas a valid option.🤖 Generated with Claude Code