#The better auth implementation with tanstck is slow
5 messages · Page 1 of 1 (latest)
Hi @north wedge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
You’re not alone in seeing slowness with Better Auth + Convex, especially when combined with TanStack. The knowledge we have points to a few known causes and current limitations:
-
Better Auth itself adds latency
- The Better Auth HTTP endpoints (e.g.
get-session, token endpoints) currently involve multiple Convex function calls under the hood, which makes them noticeably slower than a single Convex Auth mutation. 200ms+ per auth verification has been observed and acknowledged by the Convex team as “high right now.” [Auth latency; Next.js perf] - This is a known issue; improving performance of Better Auth + Convex is an active priority, but there’s no documented fix yet in the sources.
- The Better Auth HTTP endpoints (e.g.
-
More function calls than Convex Auth
- Compared to
convex-auth, Better Auth tends to generate more HTTP action calls and internal Convex calls, which can significantly increase total function count and perceived slowness. One user reported “more than doubled” function calls after switching. [Next.js perf; Authjs thread]
- Compared to
-
TanStack-specific behavior can amplify the problem
- With TanStack (Start/Router/Query), loaders and queries can fire very early and in parallel, sometimes before Convex has finished authenticating the user, leading to extra failed calls and retries or “unauthenticated” errors. This has been seen with both Clerk and Convex Auth, and the same pattern will affect Better Auth. [TanStack SSR issues; Convex auth + TanStack race]
-
What you can realistically do right now (based on sources)
The docs and threads don’t provide a complete “fix,” but they suggest a few mitigations you can try:-
Avoid firing authenticated queries before auth is ready
For component-level queries, Convex recommends using theskipoption (inuseQueryfromconvex/react) so that queries that require auth don’t run until you know the user is authenticated. [TanStack SSR issues]
With TanStack Query, you’d mirror that idea by conditionally enabling queries only after your Better Auth client reports a valid session (the exact code pattern isn’t in the sources, but the concept is). -
Be careful with router loaders / prefetching
In TanStack Start, loaders can run before Convex auth is established, causing unauthenticated errors and extra calls. One user had to adjust router configuration (e.g. preload behavior) to reduce these issues, though the exact “best” setup isn’t documented. [TanStack SSR issues]
-
- Follow the TanStack + Better Auth guide exactly
Make sure your setup matches the official TanStack Start + Better Auth + Convex guide, including theconvexClient()plugin on the Better Auth client and the router wiring. Misconfigurations there have caused odd behavior and extra calls for others. [TanStack guide; Infinite loading thread]
- Expectation setting
- The Convex team has explicitly said that Better Auth performance is a known issue and is being worked on; some users have reverted to
convex-authbecause Better Auth “felt much slower to login” and increased function counts. [Authjs thread; Next.js perf] - The knowledge sources do not yet document a configuration that makes Better Auth + Convex + TanStack as fast as Convex Auth.
- The Convex team has explicitly said that Better Auth performance is a known issue and is being worked on; some users have reverted to