nuxthub-better-auth
nuxthub-better-auth copied to clipboard
A demo of using Better Auth with Nuxt & NuxtHub (Cloudflare D1 & KV).
NuxtHub x BetterAuth
A demo of using BetterAuth with NuxtHub (Cloudflare Pages with D1 & KV).
https://better-auth.nuxt.dev
Features
- Server-Side rendering on Cloudflare Workers
- SQL Database on the edge
- Use Key Value Storage as secondary storage for sessions, etc.
useAuth()Vue composable for easy authenticationserverAuth()composable for accessing Better Auth instance on the server- One click deploy on 275+ locations for free
Setup
Make sure to install the dependencies with pnpm:
pnpm install
Copy the .env.example file to .env and update the variables with your own values.
The BETTER_AUTH_SECRET should be a random string of your choosing used by Better Auth for encryption and generating hashes.
The GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET should be your GitHub OAuth application credentials (see create an OAuth application).
The NUXT_UI_PRO_LICENSE should be your Nuxt UI Pro license key (only required for production), if you don't have one, you can purchase one here.
Development Server
Start the development server on http://localhost:3000:
pnpm dev
Production
Build the application for production:
pnpm build
Deploy
Deploy the application on the Edge with NuxtHub on your Cloudflare account:
npx nuxthub deploy
Then checkout your server logs, analaytics and more in the NuxtHub Admin.
You can also deploy using Cloudflare Pages CI.
Database Migrations
Right now, we don't automatically run migrations on deployment. You can manually run them by visiting the /api/migrate endpoint after deploying.