Auth0Rengarajan RAnnouncement
Introducing the Auth0 SDK for TanStack Start
Summary
Auth0 released a dedicated SDK for TanStack Start, a full-stack React framework, to replace hand-rolled OIDC flows or adapted SDKs. The SDK provides hooks, components, route guards, server middleware, and server helpers that integrate with TanStack Start’s server functions, middleware, and file-based router. Setup involves installing the package, configuring environment variables for the Auth0 application, creating a server-side Auth0 instance, registering the auth0Middleware in the start file, and wiring the router context and Auth0Provider in the root route. The SDK automatically mounts auth routes for login, callback, logout, profile, and backchannel logout, and supports features like login, logout, protected routes via requireAuth, session reading on the server with getSession, and additional capabilities such as passkeys, organizations, MFA, and API scope checks. The fastest way to try it is the official quickstart, which scaffolds a fresh app and adds the SDK step by step.
Context
Auth0 released a dedicated SDK for TanStack Start, a full-stack React framework, to address the lack of native authentication integration. The SDK is purpose-built for TanStack Start’s server functions, middleware, and file-based router, providing typed router context, route guards, and server helpers.
Approach / What changed
Install @auth0/auth0-tanstack-start-react, configure AUTH0_DOMAIN, AUTH0_CLIENT_ID, AUTH0_CLIENT_SECRET, AUTH0_SECRET, and APP_BASE_URL environment variables, create a server-side Auth0 instance using auth0Server(), register auth0Middleware in the start file, wire auth0RouterContext in the router and wrap the app in Auth0Provider, then use hooks like useLogin, useLogout, and route guards like requireAuth to add authentication.
Takeaways
The SDK provides hooks (useAuth0, useUser, useLogin, useLogout), components (SignedIn, SignedOut), route guards (requireAuth, requireOrg), server middleware (requireAuthMiddleware, withApiAuth), and server helpers (getSession, getAccessToken) that integrate directly with TanStack Start’s primitives.
Setup requires installing the package, configuring environment variables, creating a server-side Auth0 instance, registering auth0Middleware in the start file, and wiring the router context and Auth0Provider in the root route.
The SDK automatically mounts auth routes (/auth/login, /auth/callback, /auth/logout, /auth/profile, /auth/backchannel-logout) once middleware is registered, and supports additional features like passkeys, organizations, MFA, and API scope checks through the same middleware and guard pattern.
FAQ
How do I protect a route in TanStack Start using the Auth0 SDK?
Use the requireAuth guard in the route's beforeLoad option. For example, in a dashboard route, add beforeLoad: requireAuth({ returnTo: '/dashboard' }). Unauthenticated visitors are redirected to login and sent back to the intended route afterward.
How do I read the session on the server with this SDK?
Use the getSession and getAccessToken functions exported from @auth0/auth0-tanstack-start-react/server, passing your auth0 instance as the first argument. For example, const session = await getSession(auth0); const token = await getAccessToken(auth0);
What is the difference between this SDK and a generic OIDC client for TanStack Start?
A generic OIDC client can handle login but does not provide typed router context, route guards that plug into beforeLoad, or session helpers that work inside TanStack Start's server functions. This SDK is built against TanStack Start's primitives directly, so authentication state flows through the router like loader data.
Source and freshness
- Source
- auth0.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.