From zero to deployed SaaS with auth, payments, and email
A fully functional SaaS app with user authentication, subscription payments, transactional email, and production deployment.
Next.js handles the frontend and API routes. Supabase provides the Postgres database and user authentication. Stripe processes subscription payments via webhooks that hit your Next.js API routes. Resend sends transactional emails triggered by server-side events. Vercel deploys everything automatically on git push.
Create a new Next.js app with TypeScript, Tailwind CSS, and the App Router.
npx create-next-app@latest my-saas --typescript --tailwind --eslint --app --src-dir
cd my-saas
npm run dev
"dev": "next dev --turbo" to your package.json scripts for faster development builds with Turbopack.Create a Supabase project, install the client libraries, and configure authentication.
@supabase/supabase-js and @supabase/ssr.env.local file with your credentialsnpm install @supabase/supabase-js @supabase/ssr
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
import { createBrowserClient } from '@supabase/ssr'
export function createClient() {
return createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
)
}
Create signup, login, and auth callback routes using Supabase Auth with server-side validation.
/app/signup/page.tsx with email and password fields/app/login/page.tsx/app/auth/callback/route.ts for OAuth and email confirmation/app/dashboard/page.tsx that requires loginimport { createServerClient } from '@supabase/ssr'
import { NextResponse } from 'next/server'
import { cookies } from 'next/headers'
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const code = searchParams.get('code')
if (code) {
const cookieStore = cookies()
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{ cookies: { /* cookie handlers */ } }
)
await supabase.auth.exchangeCodeForSession(code)
}
return NextResponse.redirect(new URL('/dashboard', request.url))
}
Install Stripe, create products and prices in the dashboard, and build a checkout flow with webhooks.
npm install stripe.env.local/api/checkout/route.ts that creates a Checkout Session/api/webhooks/stripe/route.ts to process subscription eventsprofiles tablenpm install stripe
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
import Stripe from 'stripe'
import { NextResponse } from 'next/server'
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
export async function POST(req: Request) {
const { priceId, userId } = await req.json()
const session = await stripe.checkout.sessions.create({
mode: 'subscription',
payment_method_types: ['card'],
line_items: [{ price: priceId, quantity: 1 }],
success_url: `${process.env.NEXT_PUBLIC_URL}/dashboard?success=true`,
cancel_url: `${process.env.NEXT_PUBLIC_URL}/pricing`,
metadata: { userId }
})
return NextResponse.json({ url: session.url })
}
stripe listen --forward-to localhost:3000/api/webhooks/stripe to test webhooks locally.Configure Resend to send welcome emails, payment receipts, and other transactional messages.
npm install resend.env.localsrc/lib/email.tsnpm install resend
import { Resend } from 'resend'
const resend = new Resend(process.env.RESEND_API_KEY)
export async function sendWelcomeEmail(email: string, name: string) {
await resend.emails.send({
from: 'Your SaaS <hello@yourdomain.com>',
to: email,
subject: `Welcome to the app, ${name}!`,
html: `<h1>Welcome aboard!</h1><p>Your account is ready.</p>`
})
}
Push to GitHub and deploy your SaaS to production with environment variables and CI/CD.
git init
git add .
git commit -m "Initial SaaS app"
git remote add origin https://github.com/you/my-saas.git
git push -u origin main
A fully functional SaaS app with user authentication, subscription payments, transactional email, and production deployment.
Get a step-by-step checklist, setup order, and the exact config for every tool in this guide. Or let me build it for you.
Get the checklist → Want this built for you?