Skip to content

fix(api): pass merged env to c.env in dev server - #2191

Merged
koistya merged 2 commits into
kriasoft:mainfrom
devtanluc:main
Oct 2, 2026
Merged

koistya merged 2 commits into
kriasoft:mainfrom
devtanluc:main

Conversation

@devtanluc

@devtanluc devtanluc commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Under bun dev, the Google sign-in button never renders even with GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET set in .env.local. config.socialProviders returns [].

Cause

apps/api/dev.ts merges process.env over the Wrangler bindings, but passes the result only to createAuth(db, env). tRPC builds ctx.env from c.env, which is {} in the Bun dev server because no bindings are passed to app.fetch(). Better Auth and tRPC therefore see different environments. Production is unaffected, since the Workers runtime fills c.env.

Any procedure that reads ctx.env was broken in dev, for example the ones that depend on Stripe variables.

Fix

Assign the merged env to c.env before next():

c.set("auth", createAuth(db, env));
c.env = env; // tRPC copies c.env into ctx.env; keep it in sync with auth
await next();

The assignment is per request, so shared bindings are not mutated.

Verification

  • Ran apps/api/dev.ts with Google credentials set: config.socialProviders returns [] before the change and ["google"] after
  • bun run test --run, bun typecheck, bun lint and bun run format:check pass
  • Not tested on Windows (the reporter's platform)
  • No regression test: it would need heavy mocking of Wrangler and the database for a one-line change

devtanluc and others added 2 commits October 2, 2026 13:08
The merged env already satisfies Env, so the cast only hid future type drift.
@koistya
koistya merged commit dbdb0d4 into kriasoft:main Oct 2, 2026
2 checks passed
@koistya

koistya commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Merged. Thanks @devtanluc, and welcome! Nice first PR – the debug output in the description made this a 10-second review. Google button now shows up in dev. Come break something else 😄

Sign up for free to 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