Auth on the edge,
wired in an afternoon.
A reference implementation of better-auth-cloudflare inside a TanStack Start app, deployed to Cloudflare Workers with D1 and KV. Everything you need to copy, learn, and ship.
What this example ships with.
- email + password, sessions signed from worker env
- drizzle orm against cloudflare d1
- rate-limit state in a cloudflare kv namespace
- protected routes via _authd layout in tanstack router
Four commands to local auth.
The full walkthrough lives in the README. This is the trail of breadcrumbs for people who learn by running things.
- Provision
pnpm wrangler d1 create db·pnpm wrangler kv namespace create kv - Generate
pnpm generate:auth→generate:cf-types→generate:db - Migrate
pnpm migrate:dev - Run
pnpm dev
Also needed in
.env.local: BETTER_AUTH_SECRET, BETTER_AUTH_URL.Where to look first.
src/lib/auth.tsserver better-auth config · d1 · kv · cloudflare pluginsrc/lib/auth-client.tsbrowser clientsrc/routes/api/auth/$.tscatch-all route → better-authsrc/components/sign-in-form.tsxexample formssrc/routes/_authd.tsxprotected layout