Reusable Next.js template with Supabase auth (email/password + Google), Postgres persistence, and Vercel deployment. Demo app: calculator with per-user history.
Live demo: template-static.vercel.app — reference deployment of this template (guest calculator works without sign-in; sign-in persists history to Supabase).
- Next.js 16 (App Router) + TypeScript + Tailwind CSS v4 + shadcn/ui
- Supabase SSR auth — email/password sign-up & sign-in, Google OAuth, session refresh middleware
- Postgres + RLS —
profiles(auto-created on signup) andcalculator_historytables - Server actions — Zod-validated
saveCalculation,listHistory,clearHistory - Demo calculator — safe expression evaluator (no
eval()), keypad UI, guest session history or per-user persistence when signed in - Landing + login pages — ready to customize for new projects
-
Create a repo from this template (GitHub “Use this template”) or clone and re-point remote:
git clone https://github.com/YOUR_ORG/template-static.git my-new-app cd my-new-app rm -rf .git && git init git remote add origin [email protected]:YOUR_ORG/my-new-app.git
-
Install dependencies:
npm install
-
Configure environment:
cp .env.example .env.local
Fill in
NEXT_PUBLIC_SUPABASE_URLandNEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY(see setup checklist below). -
Apply database migrations (after Supabase project exists):
npx supabase link --project-ref YOUR_PROJECT_REF npx supabase db push
-
Run locally (see Local development), then customize pages, branding, and replace the calculator demo as needed.
Complete these steps once per Supabase project and deployment target.
- Create a project at supabase.com
- Copy Project URL →
NEXT_PUBLIC_SUPABASE_URL - Copy Publishable key (
sb_publishable_...) →NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY
(Settings → API Keys — use publishable, not legacy anon) - Run migrations:
npx supabase db push(createsprofiles+calculator_historywith RLS) - Authentication → URL configuration
- Site URL:
http://localhost:3000(dev) and your production URL (e.g.https://my-app.vercel.app) - Redirect URLs:
http://localhost:3000/auth/callback,https://my-app.vercel.app/auth/callback
- Site URL:
Email (enabled by default)
- Authentication → Providers → Email — leave enabled for native sign-up/sign-in
- Optional: Authentication → Email — disable “Confirm email” for instant access in dev, or keep it on and use the confirmation email flow
- Google Cloud Console → APIs & Services → Credentials → OAuth 2.0 Client
- Authorized redirect URI:
https://YOUR_PROJECT_REF.supabase.co/auth/v1/callback - Copy Client ID + Secret into Supabase → Authentication → Providers → Google
- Import GitHub repo at vercel.com/new
- Add environment variables (Production + Preview):
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY
- Deploy, then add the Vercel URL to Supabase Site URL and Redirect URLs (see above)
- Re-test Google sign-in on the production URL
-
npm run dev→ open/calculator, calculate2+2— guest history appears in the panel - Sign in or create an account at
/login— OAuth completes via/auth/callback - Calculate again while signed in — entry persists in Supabase after refresh
- Sign out returns to
/
cp .env.example .env.local
# Fill in NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY
npm install
npm run devOpen http://localhost:3000.
Other scripts:
| Command | Purpose |
|---|---|
npm run dev |
Start dev server (Turbopack) |
npm run build |
Production build + typecheck |
npm run start |
Serve production build |
npm run lint |
ESLint |
| Variable | Required | Notes |
|---|---|---|
NEXT_PUBLIC_SUPABASE_URL |
Yes | Project API URL |
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY |
Yes | sb_publishable_... — not legacy anon |
SUPABASE_SECRET_KEY |
No | Server-only admin jobs only |
src/
app/
(app)/calculator/ # Demo app (guest or signed-in)
auth/callback/ # OAuth code exchange
login/ # Sign-in page
components/
auth/ # Email + OAuth + sign-out
calculator/ # Demo UI
ui/ # shadcn components
lib/
actions/ # Server actions (auth, history)
auth/session.ts # User + profile helpers
calculator/evaluate.ts # Safe math evaluator
supabase/ # SSR clients + middleware helper
middleware.ts # Session refresh on each request
tokens.css # Spacing, color, motion tokens (project root)
supabase/
migrations/ # SQL schema + RLS
apply-all.sql # Optional single-file SQL for dashboard