This is a starter template for building a SaaS application using Next.js with support for authentication, Stripe integration for payments, and a dashboard for logged-in users.
Demo: nextjs-prisma-stripe-saas-starter.vercel.app/
- Seamless Login Experience: By integrating
auth.js
, we have implemented a more natural and intuitive login flow. Users can now easily log in using third-party providers (e.g., Google, GitHub), significantly improving the user experience. - Multiple Authentication Methods:
auth.js
offers flexible authentication mechanisms, supporting OAuth, Email/Password, and more, catering to diverse user needs.
- Multi-Database Support: With the introduction of
Prisma
, the project now supports bothSQLite
andPostgreSQL
, allowing developers to choose the database that best fits their requirements. - Type-Safe Database Operations:
Prisma
provides robust type safety, reducing errors in database operations and boosting development efficiency. - Simplified Database Migrations:
Prisma
's migration tools make database schema changes more straightforward and manageable.
- Clearer Code Responsibilities: We have reorganized the codebase to ensure each module and function has a clear and single responsibility, making the code easier to understand and maintain.
- Simplified Complex Logic: Through refactoring, we have streamlined complex business logic, resulting in cleaner and more extensible code.
- Improved Readability: The readability of the code has been significantly enhanced, allowing new developers to onboard and contribute more quickly.
- Integrated i18n for localized messages, allowing users to switch languages at runtime.
- Marketing landing page (
/
) with animated Terminal element - Pricing page (
/pricing
) which connects to Stripe Checkout - Dashboard pages with CRUD operations on users/teams
- Basic RBAC with Owner and Member roles
- Subscription management with Stripe Customer Portal
- Authentication with Next-auth (Email/Password + OAuth providers)
- Global middleware to protect logged-in routes
- Local middleware to protect Server Actions or validate Zod schemas
- Activity logging system for any user events
- Framework: Next.js
- Database: Postgres
- ORM: Prisma
- Authentication: Next-auth
- Payments: Stripe
- UI Library: shadcn/ui
git clone https://github.com/nextjs/saas-starter
cd saas-starter
pnpm install
- Copy the environment variables template:
cp .env.example .env
-
Update the
.env
file with your:- Database connection string
- Next-auth configuration (NEXTAUTH_SECRET, optional OAuth providers)
- Stripe keys
-
Run database migrations:
npx prisma migrate dev
- Seed the database with a default user and team:
npx prisma db seed
This will create:
- User:
[email protected]
- Password:
admin123
- Start the development server:
pnpm dev
Open http://localhost:3000 to view the application.
For Stripe webhooks during development:
stripe listen --forward-to localhost:3000/api/stripe/webhook
The template comes pre-configured with:
- Email/password authentication
- Session management with JWT
- Protected API routes using Next-auth middleware
To enable OAuth providers:
- Add your credentials to
.env
GITHUB_CLIENT_ID=your_github_id
GITHUB_CLIENT_SECRET=your_github_secret
GOOGLE_CLIENT_ID=your_google_id
GOOGLE_CLIENT_SECRET=your_google_secret
- Update
src/auth/options.ts
to include the providers
Use Stripe test card:
- Card:
4242 4242 4242 4242
- Date: Any future date
- CVC: Any 3 digits
- Push your code to a Git repository
- Connect to Vercel and deploy
- Add environment variables in Vercel settings:
DATABASE_URL=your_production_db_url
AUTH_SECRET=your_random_secret # generate with: openssl rand -base64 32
AUTH_URL=https://yourdomain.com
STRIPE_SECRET_KEY=your_live_key
Create a production PostgreSQL database and connect it through Prisma:
npx prisma migrate deploy
- Create production webhook in Stripe Dashboard
- Set endpoint to:
https://yourdomain.com/api/stripe/webhook
- Add webhook secret to
STRIPE_WEBHOOK_SECRET
in Vercel
- Replaced Drizzle ORM with Prisma migrations and schema
- Switched custom JWT auth to Next-auth implementation
- Updated database seed script to use Prisma client
- Added Next-auth middleware for route protection
- Simplified session management with built-in Next-auth methods
- update user context-> next-auth
- update 3rd oauth login -> invite/newUser logic