fix(api): pass merged env to c.env in dev server - #2191
Merged
Merged
Conversation
The merged env already satisfies Env, so the cast only hid future type drift.
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 😄 |
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.
Problem
Under
bun dev, the Google sign-in button never renders even withGOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETset in.env.local.config.socialProvidersreturns[].Cause
apps/api/dev.tsmergesprocess.envover the Wrangler bindings, but passes the result only tocreateAuth(db, env). tRPC buildsctx.envfromc.env, which is{}in the Bun dev server because no bindings are passed toapp.fetch(). Better Auth and tRPC therefore see different environments. Production is unaffected, since the Workers runtime fillsc.env.Any procedure that reads
ctx.envwas broken in dev, for example the ones that depend on Stripe variables.Fix
Assign the merged env to
c.envbeforenext():The assignment is per request, so shared bindings are not mutated.
Verification
apps/api/dev.tswith Google credentials set:config.socialProvidersreturns[]before the change and["google"]afterbun run test --run,bun typecheck,bun lintandbun run format:checkpass