
Template details
NuxtHub Better Auth
Nuxt 4 authentication template with Better Auth, deployable to Cloudflare Workers with D1 or Vercel with Turso.
About this template
NuxtHub Better Auth is a Nuxt 4 authentication boilerplate built on Nuxt Better Auth, NuxtHub, and Nuxt UI, designed to be deployed to Cloudflare Workers with D1 or Vercel with Turso while sharing the same SQLite schema and server-side session checks.
What is NuxtHub Better Auth?
NuxtHub Better Auth is a starter template that wires email, anonymous, and GitHub sign-in into a Nuxt 4 application using Nuxt Better Auth 0.3.11 with Better Auth 1.7.12. It ships a single initial database migration and route-rule-based page protection, producing a running app with session-gated pages for /user, /secret, and /admin, plus a public /about page. It runs locally on Node with a file-based SQLite database at .data/db/sqlite.db, and deploys to Cloudflare Workers with D1 or to Vercel with a Turso database. The template is hosted on GitHub and has 154 stars.
Key Features
- Nuxt 4 framework — built on Nuxt with Nuxt UI components, NuxtHub integration, and Nuxt's app, server, shared, and tooling TypeScript projects.
- Nuxt Better Auth integration —
useUserSession()returns a shared, SSR-hydrated session; auth route rules gate page access. - SQLite-based storage — a single initial migration creates the schema; local development writes to
.data/db/sqlite.db, Cloudflare uses D1, and Vercel uses Turso. - Role-based page access —
/userand/secretrequire a session while/adminadditionally requires theadminrole;requireUserSession(event)enforces access on private API handlers. - Anonymous and email sign-up — new databases contain no demo users; accounts are created through the sign-up form.
- Optional GitHub OAuth — enable via
NUXT_GITHUB_CLIENT_ID,NUXT_GITHUB_CLIENT_SECRET, andNUXT_PUBLIC_GITHUB_AUTH_ENABLED; users link GitHub from/user. - Optional demo login buttons — setting
NUXT_PUBLIC_DEMO_ACCOUNTS_ENABLED=trueshows quick-login buttons for manually created demo accounts. - Dual deployment targets — Wrangler CLI deploys Cloudflare Workers with a
DBD1 binding, or the Vercel CLI with the Turso integration supplies database credentials.
Who is it for?
- Nuxt developers who want a working authentication layer with session-gated pages instead of wiring Better Auth from scratch.
- Serverless teams targeting Cloudflare Workers with D1 or Vercel with Turso that need the same schema on both platforms.
- Teams planning private pages that need admin-role gating and server-side session enforcement as a starting reference.
How does NuxtHub Better Auth work?
- Copy
.env.exampleto.envand generate a secret with a Node crypto command intoNUXT_BETTER_AUTH_SECRET. - Run
corepack enable,pnpm install,pnpm db:migrate, thenpnpm devand open localhost:3000. - For Cloudflare, create a D1 database with Wrangler, then build, apply remote migrations, deploy, and set the auth secret as a Worker secret. For Vercel, link a project, connect Turso, add production environment variables, migrate, and deploy.
Pros and cons
- Pro: one SQLite schema targets both Cloudflare D1 and Turso, and CI runs lint, typecheck, tests, and a Node build without cloud credentials.
- Con: the initial migration creates a new schema, so existing installations need a separate data-migration plan, and databases from earlier previews with
account.issuerneed Better Auth upgrade steps.














