A starter template combining Payload CMS 3.0 with Clerk authentication, built with Next.js 15 and TypeScript.
- π Clerk Authentication - Complete user management with sign-up, sign-in, and role-based access
- π Payload CMS 3.0 - Modern headless CMS with admin panel
- β‘ Next.js 15 - Latest React framework with App Router
- ποΈ SQLite Database (easily swappable) - Lightweight database for development
- π¨ Custom Admin UI - Enhanced Payload admin with Clerk integration
- π Role-Based Access Control - Admin, user roles with granular permissions
- π± Responsive Design - Mobile-first admin interface
- π§ͺ Testing Setup - Vitest + Playwright for unit and E2E tests
- π³ Docker Support - Containerized development and deployment
- π¦ TypeScript - Full type safety throughout the application
- Node.js 18.20.2+ or 20.9.0+
- pnpm 9+ (recommended) or npm/yarn or Bun
- Clerk account (sign up free)
git clone https://github.com/carlospr-dev/payload-clerk-starter.git cd payload-clerk-starter pnpm installCopy the example environment file:
cp .env.example .envUpdate .env with your configuration:
# Database DATABASE_URI=file:./payload-clerk-starter.db # Payload PAYLOAD_SECRET=your-super-secret-key-here # Clerk Authentication NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_... CLERK_SECRET_KEY=sk_test_... NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL="/admin" NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL="/admin" NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL="/admin"- Create a new application in your Clerk Dashboard
- Copy your publishable and secret keys to
.env - Configure redirect URLs in Clerk Dashboard to match your environment
pnpm devVisit:
- Frontend: http://localhost:3000
- Admin Panel: http://localhost:3000/admin
src/ βββ app/ # Next.js App Router β βββ (frontend)/ # Public frontend routes β βββ (payload)/ # Payload admin routes β βββ my-route/ # Custom API routes βββ collections/ # Payload collections β βββ access/ # Access control functions β βββ strategies/ # Auth strategies β βββ Media.ts # Media collection β βββ Users.ts # Users collection βββ components/ # React components β βββ BeforeLogin/ # Login page components β βββ payload/ # Payload admin components βββ lib/ # Utility functions βββ providers/ # React context providers βββ types/ # TypeScript definitions This starter implements a sophisticated auth system combining Clerk and Payload:
- Super Admin: Full system access
- Admin: Content management access
- User: Basic authenticated access
The starter includes comprehensive access control patterns:
isAdminRoles: Admin-only accessisSuperAdminRoles: Super admin-only accessisAdminRolesOrSelf: Admin or own recordsisAuthenticated: Any authenticated user
- Automatic user sync between Clerk and Payload
- Role management through Payload admin
- Custom admin UI components for user management
# Development pnpm dev # Start development server pnpm devsafe # Clean start (removes .next) # Building pnpm build # Build for production pnpm start # Start production server # Code Quality pnpm lint # Run ESLint pnpm generate:types # Generate Payload types # Testing pnpm test # Run all tests pnpm test:int # Run integration tests pnpm test:e2e # Run E2E tests # Payload CLI pnpm payload # Access Payload CLI commandsRun with Docker Compose:
docker-compose up -dThis starts the application with all dependencies in containers.
Ensure these are set in production:
DATABASE_URI: Your production database URLPAYLOAD_SECRET: Strong secret keyNEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: Clerk publishable keyCLERK_SECRET_KEY: Clerk secret key- Clerk redirect URLs configured for your domain
This starter works with:
- Vercel: Deploy with zero configuration
- Railway: One-click deployment
- Docker: Use included Dockerfile
- Payload Cloud: Native Payload hosting
The starter includes comprehensive testing setup:
- Unit Tests: Vitest with React Testing Library
- E2E Tests: Playwright for full user flows
- Test Database: Separate test environment
Run tests:
pnpm test:int # Unit/integration tests pnpm test:e2e # End-to-end tests- Create new collection in
src/collections/ - Add to
payload.config.ts - Generate types:
pnpm generate:types
Extend access patterns in src/collections/access/
Modify components in src/components/payload/
- 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.
- Payload CMS for the amazing headless CMS
- Clerk for seamless authentication
- Next.js for the React framework
Need help? Open an issue or check the discussions.