knowsuchagency/cloudflare-templatePublic template
Star 12,750
SF Stephan Fitzpatrick @knowsuchagency

Better Auth + shadcn SPA on Cloudflare, in one command

A Copier template for a Cloudflare Worker that serves Better Auth and a shadcn/ui login SPA, backed by D1. Hono, Drizzle, and Vite wired up. Generate, deploy, done.

12,750 stars
▾ README.mdMarkdown

cloudflare-better-auth-d1 (copier template)

A Copier template for a Cloudflare Worker that serves Better Auth and a shadcn/ui login SPA, backed by Cloudflare D1.

Generated projects contain

  • Hono Worker with Better Auth mounted at /api/auth/* and the drizzle-orm/d1 adapter
  • Vite React SPA (shadcn/ui, radix, phosphor icons) served through the Worker's assets binding
  • Generated Drizzle schema + SQL migration for the four better-auth tables: user, session, account, verification
  • wrangler.jsonc with the D1 binding, SPA fallback, and run_worker_first: ["*/api/**"]

Usage

$ uvx copier copy gh:<owner>/<this-repo> ./my-auth-app
# or from a local checkout
$ uvx copier copy path/to/this-template ./my-auth-app

You will be asked for a project_slug (kebab-case name for the Worker and package), app_title and app_tagline (text shown in the login card), and worker_name / d1_database_name (defaults derived from the slug). After generation, Copier runs install and build, then prints the commands to create the D1 database and deploy.

Self-hosting strategy

The default rendered project is vanilla Cloudflare + D1, right for about 90 percent of projects. When it is not, a rendered project can move selected pieces onto your own infra without a rewrite. Each escape hatch is documented:

  • self-hosted-database: swap D1 for self-hosted Postgres, reached by the Worker via Hyperdrive and a Cloudflare Tunnel. The Worker stays.
  • self-hosted-runtime: swap the Worker for a Bun + Hono container on Dokploy serving both /api/* and the SPA.
  • self-hosted-object-storage: add an S3-compatible gateway reached by the Worker over a Workers VPC binding on the same tunnel.

Discussion

84
IV
Ivan K @ivanmakes · 4h

Had Better Auth + D1 deployed in minutes. The wrangler.jsonc being preconfigured is the real time-saver.

♥ 92Reply
RC
Ruth C @ruthcodes · 9h

Can I swap D1 for my own Postgres later without a rewrite?

♥ 18Reply
SF
Stephan Fitzpatrick CREATOR · 8h

Yep. The self-hosted-database doc walks through swapping D1 for Postgres via Hyperdrive and a Cloudflare Tunnel. The Worker stays put.

♥ 27Reply
DW
Dan W @danwrites · 1d

Made this our default starter for internal tools. The shadcn login screen out of the box is chef's kiss.

♥ 31Reply

Get notified when the template ships updates

New escape hatches, auth providers, and Cloudflare features. No spam, just the changelog.

Published with PageSumo