A modern authentication demo built with RedwoodJS SDK (RWSDK), Better Auth, and Prisma ORM, deployed on Cloudflare Workers with D1 Database.
- 🔒 GitHub OAuth Authentication with Better Auth
- ⚡ Edge Computing with Cloudflare Workers
- 🗄️ Type-safe Database operations with Prisma + D1
- ⚛️ React Server Components with server-side rendering
- 🎨 Modern UI with RWSDK brand colors and dark mode support
- 📱 Responsive Design with glassmorphism effects
- RedwoodJS SDK - Modern full-stack framework
- Better Auth - Secure authentication library
- Prisma - Type-safe ORM with D1 adapter
- Cloudflare Workers - Edge computing platform
- D1 Database - SQLite at the edge
- Node.js 18+
- npm or pnpm
- Cloudflare account (for deployment)
-
Clone the repository
git clone <repository-url> cd rwsdk-better-auth-prisma
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Configure the following variables:
BETTER_AUTH_URL=http://localhost:5173 OAUTH_GITHUB_CLIENT_ID=your_github_client_id OAUTH_GITHUB_CLIENT_SECRET=your_github_client_secret
-
Generate Prisma client and apply migrations
npm run generate npm run migrate:dev
-
Generate Better Auth schema
npx @better-auth/cli generate
-
Start development server
npm run dev
Visit http://localhost:5173
to see the application!
npm run dev
- Start development servernpm run build
- Build for productionnpm run types
- Run type checking
npm run generate
- Generate Prisma client and Wrangler typesnpm run migrate:dev
- Apply migrations to local databasenpm run migrate:prd
- Apply migrations to production D1 databasenpm run migrate:new
- Create new migrationnpm run check
- Run type checking after generation
npm run release
- Deploy to Cloudflare Workers
This project uses Prisma with the D1 adapter for Cloudflare Workers:
- Local Development: Uses SQLite file database
- Production: Uses Cloudflare D1 database
-
Create migration:
npm run migrate:new
-
Apply to local database:
npm run migrate:dev
-
Deploy to production:
npm run migrate:prd
-
Create GitHub OAuth App:
- Go to GitHub Settings > Developer settings > OAuth Apps
- Create a new OAuth App
- Set Authorization callback URL to:
http://localhost:5173/api/auth/callback/github
-
Configure Environment Variables:
OAUTH_GITHUB_CLIENT_ID=your_client_id OAUTH_GITHUB_CLIENT_SECRET=your_client_secret
-
Better Auth Integration:
- Better Auth handles OAuth flows automatically
- Session management integrated with Prisma
- Type-safe user authentication throughout the app
- RWSDK Brand Colors: Official orange color scheme (
#F37337
) - Dark Mode Support: True black theme with high contrast
- Modern Design: Glassmorphism effects and smooth animations
- Responsive Layout: Works on desktop, tablet, and mobile
- Interactive Elements: Hover effects and transitions
src/
├── app/
│ ├── Document.tsx # HTML document with styling
│ ├── pages/
│ │ ├── Home.tsx # Main landing page
│ │ └── user/
│ │ ├── Login.tsx # Authentication page
│ │ └── routes.ts # User route definitions
│ └── shared/
├── lib/
│ ├── auth.ts # Better Auth configuration
│ └── auth-client.ts # Client-side auth utilities
├── worker.tsx # Main application entry point
└── db.ts # Database configuration
prisma/
└── schema.prisma # Database schema
migrations/
└── 0001_better_auth.sql # Database migrations
-
Configure Wrangler:
npx wrangler login
-
Set up D1 Database:
npx wrangler d1 create your-database-name
-
Update wrangler.jsonc with your D1 database ID
-
Deploy:
npm run release
Set these in Cloudflare Workers dashboard:
BETTER_AUTH_URL
- Your production domainOAUTH_GITHUB_CLIENT_ID
- GitHub OAuth client IDOAUTH_GITHUB_CLIENT_SECRET
- GitHub OAuth client secret
-
Better Auth CLI Error:
- Ensure auth configuration doesn't use Cloudflare Workers imports during CLI execution
- The project includes runtime-compatible auth setup
-
Migration Errors:
- Check database connection string
- Ensure Prisma client is generated:
npm run generate
-
Type Errors:
- Run
npm run types
to check for issues - Regenerate types:
npm run generate
- Run
- RedwoodJS SDK Documentation
- Better Auth Documentation
- Prisma D1 Documentation
- Cloudflare Workers Documentation
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Commit changes:
git commit -m 'Add amazing feature'
- Push to branch:
git push origin feature/amazing-feature
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ using RedwoodJS SDK, Better Auth, Prisma, and Cloudflare Workers