Skip to content

πŸ” This is a template that can be deployed on Cloudflare Workers, built with React Router v7 (Remix), Better Auth, Drizzle ORM, and D1.

Notifications You must be signed in to change notification settings

foxlau/react-router-v7-better-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

86 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

React Router v7 with Better auth.

This template features React Router v7, Better auth, Drizzle ORM, and D1, designed for deployment on Cloudflare Workers.

πŸ” Authentication Features

This template implements a complete authentication system using Better Auth with the following features:

  • πŸ“§ Email and Password Authentication - Secure login with email and password
  • πŸ”‘ Password Recovery - Forgot password and reset password functionality
  • πŸ”„ Social Login - Sign in with Google and GitHub accounts
  • πŸ‘€ Session Management - Secure session handling with Cloudflare KV storage
  • πŸ—‘οΈ Account Management - Including account deletion functionality
  • πŸ‘‘ Admin Panel - Complete admin dashboard with user management, role-based access control

⭐ Core Features

  • πŸš€ Server-side rendering
  • ⚑️ Hot Module Replacement (HMR)
  • πŸ“¦ Asset bundling and optimization
  • πŸ”„ Data loading and mutations
  • πŸ”’ TypeScript by default
  • πŸŽ‰ TailwindCSS and Shadcn for UI styling
  • πŸ”‘ Better Auth for authentication
  • 🌧️ Drizzle ORM for database
  • πŸ›’οΈ Cloudflare D1 for database
  • πŸ“ Cloudflare KV for caching
  • πŸ“– React Router docs

Demo

Here's a preview of the app:

For more demo images, check the .assets directory.

Links

React Router v7 Authentication Demo Series:

Getting Started

Installation

Install the dependencies:

git clone https://github.com/foxlau/react-router-v7-better-auth.git
pnpm install

Development

Run an initial database migration:

cp .dev.vars.example .dev.vars
cp wrangler.jsonc.example wrangler.jsonc
pnpm db:apply
pnpm db:seed

If you modify the Drizzle ORM schema, please run pnpm db:generate first. If you need to delete the generated SQL migrations, execute pnpm db:drop and select the SQL migration you wish to remove.

Start the development server with HMR:

pnpm dev

Your application will be available at http://localhost:5173.

Database Commands

  • pnpm db:generate - Generate new database migration files
  • pnpm db:apply - Apply migrations to local database
  • pnpm db:apply-prod - Apply migrations to production database
  • pnpm db:drop - Remove generated SQL migrations (interactive)
  • pnpm db:seed - Seed local database with initial data from app/lib/database/seed.sql
  • pnpm db:seed-prod - Seed production database with initial data from app/lib/database/seed.sql

Default Users (from seed.sql)

  • Regular User: john@example.com / user@9900
  • Admin User: admin@example.com / admin@8899

Building for Production

Create a production build:

pnpm build

Deployment

Deployment is done using the Wrangler CLI.

Use the following commands to create the D1 database and KV cache for Better Auth sessions. Remember to replace the db and kv configurations in the wrangler.toml file with the data generated by these commands:

npx wrangler d1 create rr7-better-auth
npx wrangler kv namespace create APP_KV

To deploy directly to production:

pnpm db:apply-prod
pnpm deploy

To deploy a preview URL:

pnpm deploy:version

You can then promote a version to production after verification or roll it out progressively.

pnpm deploy:promote

Questions

If you have any questions, please open an issue.

About

πŸ” This is a template that can be deployed on Cloudflare Workers, built with React Router v7 (Remix), Better Auth, Drizzle ORM, and D1.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •