The complete production-ready Next.js starter kit for building modern lead magnet platforms with payments, authentication, and premium features.
π Built with the latest and greatest:
- β‘ Next.js 15 - React framework with App Router
- π³ Polar.sh - Modern payments for lifetime access plans
- π Better Auth - Authentication with Google OAuth and sessions
- ποΈ PostgreSQL + Drizzle ORM - Type-safe database operations
- π¨ 20+ Theme Variants - Beautiful theming system with dark mode
- π’ Production-Ready - Sidebar navigation, user management, premium features
Perfect for SaaS applications, lead generation tools, and any web app that needs user accounts with lifetime access payments.
- Email/password authentication with Better Auth
- Google OAuth provider with account linking
- Secure session management (7-day expiration)
- User preferences and profile management
- Protected route groups for premium features
- One-time payments (lifetime deals)
- Automatic customer creation and linking
- Graceful error handling for payment failures
- Customer portal managed by Polar
- 20+ built-in themes: Default, Cyberpunk Neon, Tropical Paradise, Zen Garden, etc.
- Responsive sidebar navigation with collapsible design
- Theme-aware components using CSS custom properties
- Dark/light mode support for all themes
- Mobile-first responsive design
- Dashboard with subscription status and analytics
- User profile management with avatar support
- Settings page with theme selection
- Landing page with pricing tiers
- Internationalization support (7 languages)
- TypeScript everywhere with strict mode
- Biome for fast linting and formatting
- Hot reload development server
- Docker support for easy deployment
- Comprehensive error handling
# Install pnpm (recommended package manager)
npm install -g pnpm
# Verify Node.js version (18+ required)
node --version
# Clone the repository
git clone https://github.com/cgoinglove/nextjs-polar-starter-kit.git
cd nextjs-polar-starter-kit
# Install dependencies
pnpm install
# Run post-install setup
pnpm postinstall
Create your environment file:
# Copy the example environment file
cp .env.example .env
# Or use the built-in script
pnpm initial:env
Open .env
and configure the following:
# Generate a random secret key (32+ characters)
BETTER_AUTH_SECRET=your-super-secret-key-here-make-it-long-and-random
# Base URL for authentication callbacks
BETTER_AUTH_URL=http://localhost:3000 # Local development
# BETTER_AUTH_URL=https://yourdomain.com # Production
# Get your Polar access token (see setup guide below)
POLAR_ACCESS_TOKEN=polar_at_xxxxxxxxxxxxx
# Product ID from your Polar dashboard
POLAR_LIFETIME_PRODUCT_ID=prod_xxxxxxxxxxxxx
# Local development (using Docker)
POSTGRES_URL=postgres://postgres:password@localhost:5432/polar_saas
# NeonDB (Recommended for production)
# POSTGRES_URL=postgresql://username:password@ep-cool-darkness-123456.us-east-2.aws.neon.tech/neondb?sslmode=require
# Or use other cloud providers (Supabase, Railway, etc.)
# POSTGRES_URL=postgresql://username:password@your-db-host:5432/database
# Google OAuth (optional)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
# Disable user registration (default: false)
DISABLE_SIGN_UP=false
# Allow non-HTTPS cookies for local development
NO_HTTPS=true
# Start PostgreSQL container
pnpm docker:pg
# Run database migrations
pnpm db:migrate
# (Optional) Open Drizzle Studio to view/edit data
pnpm db:studio
NeonDB is a serverless PostgreSQL database perfect for modern applications:
-
Quick Setup:
# Follow the detailed NeonDB setup guide cat NEON_SETUP.md
-
Get your NeonDB connection string and add it to
.env
:POSTGRES_URL=postgresql://username:password@ep-cool-darkness-123456.us-east-2.aws.neon.tech/neondb?sslmode=require
-
Run migrations:
pnpm db:migrate
Follow the same process as NeonDB but without the SSL requirement.
- Visit polar.sh and sign up
- Complete your organization setup
- Verify your account
- Go to Settings β API Keys in your Polar dashboard
- Click Create new token
- Name it "SaaS Kit Development"
- Copy the token (starts with
polar_at_
) - Add it to your
.env
file:POLAR_ACCESS_TOKEN=polar_at_xxxxxxxxxxxxx
-
Go to Products in your Polar dashboard
-
Create one product:
Lifetime Deal:
- Name: "Lifetime Access"
- Type: One-time
- Price: $299
- Copy the Product ID to
POLAR_LIFETIME_PRODUCT_ID
Common commands:
# Start the development server
pnpm dev
# Open your browser
# http://localhost:3000
polar-saaskit/
βββ π src/
β βββ π app/ # Next.js App Router
β β βββ π (auth)/ # Public authentication pages
β β β βββ sign-in/ # Sign in page
β β β βββ sign-up/ # Sign up page
β β βββ π (premium)/ # Protected premium features
β β β βββ app/ # Main app interface
β β β β βββ page.tsx # Dashboard with sidebar
β β β βββ layout.tsx # Premium layout
β β βββ π api/ # API routes
β β β βββ auth/ # Better Auth endpoints
β β βββ pricing/ # Landing page pricing
β β βββ page.tsx # Landing page
β β βββ layout.tsx # Root layout
β βββ π components/ # React components
β β βββ π ui/ # Reusable UI components
β β βββ π layouts/ # Layout components
β β βββ π landing/ # Landing page sections
β β βββ dashboard.tsx # Dashboard with stats
β β βββ profile.tsx # User profile
β β βββ settings.tsx # Settings with themes
β βββ π lib/ # Core libraries
β β βββ π auth/ # Authentication config
β β βββ π db/ # Database & migrations
β β βββ utils.ts # Utility functions
β β βββ const.ts # App constants
β βββ π types/ # TypeScript definitions
βββ π messages/ # Internationalization
βββ π public/ # Static assets
βββ π docker/ # Docker configuration
βββ π scripts/ # Build scripts
This starter includes 20+ beautiful themes with full dark mode support:
- Default - Clean and modern
- Zinc - Subtle and professional
- Slate - Cool blue-gray tones
- Stone - Warm neutral palette
- Gray - Classic grayscale
- Blue - Vibrant blue accents
- Orange - Energetic orange highlights
- Pink - Soft pink aesthetics
- Bubblegum Pop - Playful pink and purple
- Cyberpunk Neon - Electric blues and magentas
- Retro Arcade - 80s gaming nostalgia
- Tropical Paradise - Ocean blues and sunset orange
- Steampunk Cogs - Industrial brass and copper
- Neon Synthwave - Retro-futuristic neon
- Pastel Kawaii - Soft pastel cuteness
- Space Odyssey - Deep space blues and stars
- Vintage Vinyl - Classic record warmth
- Misty Harbor - Foggy blues and grays
- Zen Garden - Natural greens and earth tones
Users can switch themes instantly via the Settings page in the sidebar.
-
Configure Environment Variables:
- Add all required environment variables from your
.env
file - Update
BETTER_AUTH_URL
to your Vercel domain, check for www if forwarded to www - Use a production database (Neon recommended)
- Add all required environment variables from your
-
Database Setup for Production:
# Option 1: Use Neon (Recommended) # 1. Sign up at neon.tech # 2. Create a new project # 3. Copy connection string to POSTGRES_URL # Option 2: Use Vercel Postgres # 1. Go to Vercel Dashboard β Storage β Create Database # 2. Choose PostgreSQL # 3. Environment variables are auto-added
-
Run Production Migrations:
# Connect to your production database pnpm db:migrate
# Build and start with Docker Compose
pnpm docker-compose:up
# Or build manually
docker build -t polar-saas-kit .
docker run -p 3000:3000 polar-saas-kit
# Build for production
pnpm build
# Start production server
pnpm start
pnpm dev # Start development server
pnpm build # Build for production
pnpm start # Start production server
pnpm lint # Run Biome linter
pnpm format # Format code
pnpm db:generate # Generate new migrations
pnpm db:migrate # Run pending migrations
pnpm db:studio # Open Drizzle Studio
pnpm db:push # Push schema changes (dev only)
pnpm docker:pg # Start PostgreSQL only
pnpm docker:app # Start app only
pnpm docker-compose:up # Start full stack
pnpm docker-compose:down # Stop all services
pnpm initial:env # Generate .env from .env.example
pnpm postinstall # Post-installation setup
pnpm clean # Clean build artifacts
- User signs up/in β Better Auth handles authentication
- Polar customer created β Automatic customer linking
- Session established β 7-day session with refresh
- Route protection β Access to premium features
- User selects plan β Redirected to Polar checkout
- Payment processed β Polar handles payment securely
- Webhook received β Subscription status updated
- Access granted β Premium features unlocked
- User table - User accounts and preferences
- Session table - Authentication sessions
- Account table - OAuth provider accounts
- Verification table - Email verification codes
Contributions are welcome! Please read our contributing guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow the existing code style (Biome formatting)
- Add TypeScript types for all new code
- Write JSDoc comments for functions
- Test authentication flows thoroughly
- Use theme-aware CSS custom properties
- Documentation: Check the cursor rules for detailed development guidelines
- Issues: GitHub Issues
- Discussions: GitHub Discussions
If this starter kit helps you build amazing SaaS applications, consider sponsoring the development:
Your support helps maintain and improve this project for the entire community.
This project is licensed under the MIT License - see the LICENSE file for details.
- Next.js - The React framework for production
- Better Auth - Modern authentication for web apps
- Polar.sh - Simple, powerful payments for developers
- Drizzle ORM - TypeScript ORM for SQL databases
- Tailwind CSS - Utility-first CSS framework
- Radix UI - Accessible component primitives
Built with β€οΈ by prosamik