Can't get better-auth working with the Tanstack Start and Convex stack
The weird part is the error gives me to nothing to work with, just
fetch failed and even weirder is that it wouldn't happen on every reload, but when the page does reload, client interactivity wouldn't work, meaning no onClick handler stuff is working.
Neither server nor browser console tells me anything. Have followed, checked and rechecked the setup process. https://convex-better-auth.netlify.app/framework-guides/tanstack-startTanStack Start | Convex + Better Auth
Install and configure Convex + Better Auth for TanStack Start.

41 Replies
Update: Every single call to the api/auth/$.ts path gives 500 internal server error.
I'm sorry I don't know tanstack
What version of TanStack Start are you using
Used better-t-stack to scaffold the project.
"@tanstack/react-start": "^1.121.0-alpha.27",
I have the updated the necessary packages to their latest versions, and Tanstack Start is now on RC version. Saw your comment over at Github that you're updating the library, docs and example to the RC. Is it still being worked on or live?not live yet
it happens in Node because when the route is built, it uses the WebAPI Request and undici, the default HTTP client in Node, doesn't like that.
After the Vercel CEO fiasco I finally moved to Cloudflare and to be done with it
Hi there, I tested this out last night and it give me the same error in development, do you have it running on local host too? If so, do you mind sharing steps on how to solve this?
I've explained some here,
https://discord.com/channels/1019350475847499849/1423276934787366963
I've also tested it with social and email sign in,
My environment variable are correct as far as i can tell, but for both cases i get dom exception
If you wrap that in a try catch you will see that the error comes from undici. I don't remember exactly what the error was, but it had to do with the different implementation of Request in undici compared to the WebAPI. What I did was to just copy the code in reactStartHandler and modified to work with undici/Node
so if you're in a Node environment, as you probably are, just import Request from undici and modify the code accordingly
Yeah it's an error 500 regarding some dom exception, and how did you update it to that?
Oh! Okay i will try that today
Thank you
this is my current code, but it's for cloudflare workers
instead of using Request directly, you would have to import it from unidici and modify it to fit your needs
Let me run this and I'll get back to you
though my runtime is bun for the dev env. I do plan to deploy my application on the cloudflare workers as well.
After updating to RC, TS is screaming at me, seems a lot of schema has been changed, so will wait for the docs to get updated prolly.
it was still erroring even after that update, but this guy over here made it work somehow, I'm getting 404 now, but at least its not a 500 with no context,
https://github.com/get-convex/better-auth/issues/118
GitHub
Bug Report: reactStartHandler fails with AbortError due to missing ...
Environment Package: @convex-dev/better-auth@0.8.6 Framework: TanStack Start ^1.132.27 Node.js: ^20.19.9 (with modern Fetch API) Runtime: Node.js server-side handlers Description The reactStartHand...
I managed to solve mine like this thanks to the OP and AI
https://github.com/get-convex/better-auth/issues/118#issuecomment-3369132822
The better auth library not being compatible with Tanstack RC is my current barrier rn.
does your convexClient() fn gives error in plugin?
Not
Thanks to the patch I made thanks to claude and put on the github now it's working
I got some issues with the detection of the fact I'm signed in but now it's working
could you share the final code of it, code and screenshots look a little confusing, just checked, if its not too much work
I have made the necessary migration changes for 0.9, but get this error when any route is loaded

Check your router.tsx and make sure it's exporting a function called getRouter https://convex-better-auth.netlify.app/framework-guides/tanstack-start#add-route-context
That error looks like TanStack isn't finding that function where it expects it.
Oh hmm the example app has src/router.tsx, but the docs have src/routes/router.tsx, maybe that's it
hmm, I did compare my code with the docs one, and indeed
getRouter() function wasn't being exported. While that has been taken care of, another unhelpful erroir is being thrown now. I am literally going to cry
If there are one or more places where your implementation doesn't match what's documented, you're going to have some issues
getWebRequest isn't mentioned anywhere in the docs or examples currently
Did you go from 0.7 to 0.9 or were you already on 0.8?
The 0.8 guide mentions to go through the last few steps of the tanstack guide to cover updates specific to tanstack: https://convex-better-auth.netlify.app/migrations/migrate-to-0-8#framework-specific-changes
0.8.4 according to git, but that wouldn't help either cuz it wasn't working at time either, was waiting for 0.9 to release.
Gotcha - I would go through the TanStack guide and get everything aligned: https://convex-better-auth.netlify.app/framework-guides/tanstack-start
TanStack Start | Convex + Better Auth
Install and configure Convex + Better Auth for TanStack Start.
I honestly am clueless now, till last night it was entirely different shit. I even tracked the getWebRequest part and may have fixed it. But, back to square one, getting the
fetch failed error due to the same undici related stuffWent through the guide so many times, not sure where the discrepancy is...

The private property errors generally mean you have multiple copies of the convex dependency. What package manager are you using?
bun: it is in a monorepo architecture
Yeah bun would have been my guess. Look for multiple convex dependencies and see if they're conflicting.
oh yeah it's right there in the error, convex is installed as a dependency in both the root and apps/web
you'll want to limit it to just installing in apps/web and wherever your backend is, probably packages/backend
huh, that's weird since I used Better-T-Stack to scaffold the project. Wasn't even sure about this.
Try pnpm instead of Bun. I think Bun is great, but I've seen a fair amount of esoteric issues come through that are Bun specific.
yeah… I think too, though I think changing the runtime and package manager will add another overhead.
I think I should’ve gone with Astro, and then used React inside. Way too many new technologies in one stack got me overwhelmed
I really think Bun is your only issue here, fwiw
Obviously can't be certain, but that's my suspicion
But yeah, definitely make the moves you need to make to ship! 🫡
Does the Tanstack plus convex example uses pnpm for its PM?
hmm will consider this
No, npm for everything, but you're doing monorepo, hence the pnpm recommendation
I haven't really seen issues come down to "oh it's pnpm", I've seen many where the culprit is Bun
And to be fair to Bun, maybe it's just config errors and not Bun itself. But again, it's the only package manager I've seen a good amount of issues from.
haha fair, will check into this…
Hey do we need to explicitly build the core schema that better auth requires, like user, session, account, or the package handles it for us?
So, I did scaffold a project using pnpm this time, it scaffolds a todo app, runs fine as long as you are in the homepage, but navigate to dashboard or todos page, and it throws an unhandled, 500 HTTPError
my-better-t-app – Better-T-Stack
View and share your custom tech stack configuration
scaffold using pnpm
Hey @erquhart I am confused between if I should have two user table, one in betterAuth component and one in app?
Most folks go that route
I was running into errors but after moving the router.tsx files/changes to the appropriate location it seems to work now 🙏
can't believe the guide led me astray 😔