Repository navigation
fix(auth): stop prod magic-link from hitting localhost and missing apikey - #341
Merged
Merged
Conversation
…ikey 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]>
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]>
1 of 3 tasks
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
Fixes two bugs that combined to break magic-link on
app.scaffald.com:http://127.0.0.1:54321/...baked in.EXPO_PUBLIC_SCAFFALD_API_URLwas set in.env(the dev fallback). Expo loads.envbefore.env.production, and.env.productiondoesn't define this var, so the localhost value survived into the prod web bundle. Every Scaffald-SDK call from a user's browser was routed to localhost.400 {"message":"No API key found in request"}because the SDK only sentAuthorization, never theapikeyheader that Kong requires on/functions/v1/*.What this PR changes
.env.template— adds a prominent warning thatEXPO_PUBLIC_SCAFFALD_API_URLshould NEVER be set. The fallback injobs-sdk-context.tsxderives${SUPABASE_URL}/functions/v1/api, which is correct in every env. (.envis gitignored — devs need to remove the line from their local copy.)packages/scf-core/utils/jobs-sdk-context.tsx— passesEXPO_PUBLIC_SUPABASE_ANON_KEYto the SDK via the new typedanonKeyfield soHttpClientemits theapikeyheader on every request.packages/sdksubmodule bump → a2bd925 — picks up Scaffald/sdk#6, which adds the typedanonKeyfield andapikeyheader emit.Verification
Built
apps/scaffaldin prod mode (APP_ENV=production NODE_ENV=production pnpm web:build) after clearing Metro's system cache (/private/var/folders/.../T/metro-cache— see test-plan note below). In the freshentry-*.js:✅
127.0.0.1gone, prod URL intact,apikeyemit present.Test plan
rm -rf /private/var/folders/*/T/metro-*). Without this, Metro retains the previously inlined env var across builds — bit me twice during diagnosis.APP_ENV=production NODE_ENV=production pnpm web:buildinapps/scaffald).apps/scaffald/distto wherever servesapp.scaffald.com.app.scaffald.com/auth/login, attempt magic-link.https://auth.scaffald.com/functions/v1/api/v1/auth/magic-linkand carries bothAuthorization: Bearer …andapikey: …headers.🤖 Generated with Claude Code