Back to templates

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 — /user and /secret require a session while /admin additionally requires the admin role; 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, and NUXT_PUBLIC_GITHUB_AUTH_ENABLED; users link GitHub from /user.
  • Optional demo login buttons — setting NUXT_PUBLIC_DEMO_ACCOUNTS_ENABLED=true shows quick-login buttons for manually created demo accounts.
  • Dual deployment targets — Wrangler CLI deploys Cloudflare Workers with a DB D1 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?

  1. Copy .env.example to .env and generate a secret with a Node crypto command into NUXT_BETTER_AUTH_SECRET.
  2. Run corepack enable, pnpm install, pnpm db:migrate, then pnpm dev and open localhost:3000.
  3. 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.issuer need Better Auth upgrade steps.

Screenshot of NuxtHub Better Auth