Skip to content

proSamik/nextjs-polar-betterauth-onetimepurchase-starter-kit-for-saas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Onetime purchase starter kit

Deploy with Vercel

GitHub Sponsors

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.

✨ Features

πŸ” Authentication & User Management

  • 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

πŸ’³ Payments & Billing (Polar.sh)

  • One-time payments (lifetime deals)
  • Automatic customer creation and linking
  • Graceful error handling for payment failures
  • Customer portal managed by Polar

🎨 Premium UI & Theming

  • 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

🏒 Production Features

  • 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)

πŸ› οΈ Developer Experience

  • TypeScript everywhere with strict mode
  • Biome for fast linting and formatting
  • Hot reload development server
  • Docker support for easy deployment
  • Comprehensive error handling

πŸš€ Quick Start

Prerequisites

# Install pnpm (recommended package manager)
npm install -g pnpm

# Verify Node.js version (18+ required)
node --version

1. Clone and Install

# 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

2. Environment Setup

Create your environment file:

# Copy the example environment file
cp .env.example .env

# Or use the built-in script
pnpm initial:env

3. Configure Environment Variables

Open .env and configure the following:

πŸ” Required - Authentication

# 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

πŸ’³ Required - Polar.sh Payments

# 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

πŸ—„οΈ Required - Database

# 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

πŸ”— Optional - OAuth Providers

# Google OAuth (optional)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret

βš™οΈ Optional - Additional Settings

# Disable user registration (default: false)
DISABLE_SIGN_UP=false

# Allow non-HTTPS cookies for local development
NO_HTTPS=true

4. Database Setup

Option A: Local PostgreSQL with Docker (Recommended)

# Start PostgreSQL container
pnpm docker:pg

# Run database migrations
pnpm db:migrate

# (Optional) Open Drizzle Studio to view/edit data
pnpm db:studio

Option B: NeonDB (Recommended for Production)

NeonDB is a serverless PostgreSQL database perfect for modern applications:

  1. Quick Setup:

    # Follow the detailed NeonDB setup guide
    cat NEON_SETUP.md
  2. 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
  3. Run migrations:

    pnpm db:migrate

Option C: Other Cloud Database Providers

Follow the same process as NeonDB but without the SSL requirement.

5. Polar.sh Setup (Payment Provider)

Step 1: Create Polar Account

  1. Visit polar.sh and sign up
  2. Complete your organization setup
  3. Verify your account

Step 2: Get Access Token

  1. Go to Settings β†’ API Keys in your Polar dashboard
  2. Click Create new token
  3. Name it "SaaS Kit Development"
  4. Copy the token (starts with polar_at_)
  5. Add it to your .env file:
    POLAR_ACCESS_TOKEN=polar_at_xxxxxxxxxxxxx

Step 3: Create Products

  1. Go to Products in your Polar dashboard

  2. Create one product:

    Lifetime Deal:

    • Name: "Lifetime Access"
    • Type: One-time
    • Price: $299
    • Copy the Product ID to POLAR_LIFETIME_PRODUCT_ID

6. Start Development

Common commands:

# Start the development server
pnpm dev

# Open your browser
# http://localhost:3000

πŸ—οΈ Project Structure

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

🎨 Theme System

This starter includes 20+ beautiful themes with full dark mode support:

Base Themes

  • 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

Special Themes

  • 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.

🌐 Deployment

Vercel Deployment (Recommended)

  1. Deploy to Vercel: Deploy with Vercel

  2. 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)
  3. 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
  4. Run Production Migrations:

    # Connect to your production database
    pnpm db:migrate

Docker Deployment

# 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

Manual Deployment

# Build for production
pnpm build

# Start production server
pnpm start

πŸ› οΈ Development Commands

Core Commands

pnpm dev                  # Start development server
pnpm build               # Build for production  
pnpm start               # Start production server
pnpm lint                # Run Biome linter
pnpm format              # Format code

Database Commands

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)

Docker Commands

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

Utility Commands

pnpm initial:env         # Generate .env from .env.example
pnpm postinstall         # Post-installation setup
pnpm clean               # Clean build artifacts

πŸ›οΈ Architecture

Authentication Flow

  1. User signs up/in β†’ Better Auth handles authentication
  2. Polar customer created β†’ Automatic customer linking
  3. Session established β†’ 7-day session with refresh
  4. Route protection β†’ Access to premium features

Payment Flow

  1. User selects plan β†’ Redirected to Polar checkout
  2. Payment processed β†’ Polar handles payment securely
  3. Webhook received β†’ Subscription status updated
  4. Access granted β†’ Premium features unlocked

Database Schema

  • User table - User accounts and preferences
  • Session table - Authentication sessions
  • Account table - OAuth provider accounts
  • Verification table - Email verification codes

🀝 Contributing

Contributions are welcome! Please read our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • 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

πŸ“§ Support

πŸ’– Sponsor

If this starter kit helps you build amazing SaaS applications, consider sponsoring the development:

GitHub Sponsors

Your support helps maintain and improve this project for the entire community.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


Built with ❀️ by prosamik

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages