Repository navigation
fix(templates): support web and native together in Convex Better Auth - #1294
Conversation
Resolve the Better Auth base URL per request when Next.js or TanStack Start ships with a native app, so web requests proxied through the app keep the site URL and native requests sent straight to Convex use the Convex site URL. Trust the Expo Web dev origin when a web frontend also exists. Fixes #745 Fixes #669
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5088b4aad0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe change adds a Next.js and Expo Uniwind build sample with Convex and Better Auth. It also updates Better Auth URL and trusted-origin settings for specified native frontend combinations. ChangesNative Better Auth configuration
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Provision CONVEX_SITE_URL for mixed web/native projects. · auth.ts.hbs:32-38
packages/template-generator/templates/auth/better-auth/convex/backend/convex/auth.ts.hbs:32-38
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winProvision
CONVEX_SITE_URLfor mixed web/native projects.The generated Better Auth configuration includes
process.env.CONVEX_SITE_URLinallowedHosts, but the mixed Next.js/native and TanStack Start/native generator branches do not provision this backend variable. For a native request sent directly to the Convex site, Better Auth 1.6.17 ignores the undefined host pattern, finds no allowed host, and appliesfallback: siteUrl. The native request therefore resolves auth URLs to the web site instead of the Convex site.Add the backend
CONVEX_SITE_URLvariable and its setup instruction in both affected generator branches.
ℹ️ Review info
⚙️ Run configuration
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
1eb1551e-d978-4c59-a0cb-763b9d63f020
⛔ Files ignored due to path filters: 1
packages/template-generator/src/templates.generated.tsis excluded by!**/*.generated.*
📒 Files selected for processing: 1
apps/cli/test/generated-builds/samples.ts
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
Summary
Fixes Convex + Better Auth scaffolds that have both a web frontend and a native (Expo) frontend.
convex/auth.tspinnedbaseURL: siteUrl, so native social sign-in sent OAuth callbacks to the web app's origin (for examplelocalhost:3001, which a device can't reach). For this combination,baseURLis now a dynamic config:allowedHosts: [siteUrl, process.env.CONVEX_SITE_URL!], withfallback: siteUrl, andadvanced.trustedProxyHeaders: true. Web requests that pass through the Next/Start/api/authproxy still resolve to the site URL, because the proxy setsx-better-auth-forwarded-hostand the component turns it back intox-forwarded-host. Native requests that go straight to Convex resolve to the.convex.siteURL. Only those two hosts are accepted. Web-only Next and Start output is unchanged (baseURL: siteUrl).SITE_URLandcrossDomain({ siteUrl })point at the web app, so Expo Web (http://localhost:8081) was neither a trusted origin nor allowed by CORS, which caused "Failed to fetch". Web + native setups now addhttp://localhost:8081totrustedOrigins, the same way the non-Convex Better Auth server template already does. Native-only output is unchanged.next-expo-convex-better-authgenerated-build sample (Next + native-uniwind).expectAuthis not added.Docs followed
baseURL, because the client points atCONVEX_SITE_URL. For Expo Web it says to add the site URL totrustedOrigins, usecrossDomain, setcors: true, and pickcrossDomainClientorexpoClientby platform. The generated native client already follows this.baseURL: siteUrl, used through the framework proxy. This is kept for web-only setups.baseURLwithallowedHosts/fallback,advanced.trustedProxyHeaders) and the Better Auth Expo integration (trustedOriginswith the app scheme andexp://).Not tested live
I did not run OAuth or session flows against a live Convex deployment. The changes were checked through generation, typechecking, builds, and by reading the
@convex-dev/better-auth0.12.5 andbetter-auth1.6.17 source (proxy header forwarding and dynamic base URL resolution).Verification
bun run check: passescd apps/cli && bun run test:ci: 112 pass, 0 failBTS_BUILD_SAMPLES=1 BTS_BUILD_SAMPLE_FILTER=convex bun test test/generated-builds.test.ts: 7 pass, 0 fail, including the new sample (install, check-types, build,expo exportfor iOS and Android)create-json: next + native-uniwind, tanstack-start + native-bare, tanstack-router + native-unistyles, native-only, and next-only. Ranbun installandbun run check-typeson each and all pass (the Vite web apps need non-placeholderVITE_CONVEX_*values for varlock). I also read the generatedconvex/auth.tsfor each. next-only still emitsbaseURL: siteUrl, trustedOrigins: [siteUrl].Summary by CodeRabbit
localhost:8081as a trusted origin for supported native frontend combinations, including Next.js, TanStack Start, TanStack Router, React Router, Nuxt, Svelte, and Solid.