Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.
Shell agent-teamsai-agentai-automationanthropicautonomous-agentawsbusiness-operationsclaudeclaude-codeclaude-code-plugindevopsecommerceinbox-zeroklaviyomarketingmcpmorning-briefingpr-automationshopifyterminal
Replace nextjs-saas Auth.js with Clerk and document setup
Cursor Agentee4a5af01a4b
diff --git a/claude-ops/CHANGELOG.md b/claude-ops/CHANGELOG.mdindex e4f01266..5bd10670 100644--- a/claude-ops/CHANGELOG.md+++ b/claude-ops/CHANGELOG.md@@ -2,6 +2,12 @@All notable changes to this project will be documented in this file.+## [Unreleased]++### Changed++- **`templates/nextjs-saas/`** — Replaced Auth.js (next-auth) with [Clerk](https://clerk.com): `@clerk/nextjs`, `ClerkProvider`, `middleware.ts` with `clerkMiddleware` + `createRouteMatcher`, `<SignIn />` / `<SignUp />` at `/login` and `/register`, and `UserButton` in the dashboard layout. Prisma `User` now stores `clerkUserId` (unique); NextAuth `Account`, `Session`, and `VerificationToken` models removed. Added `lib/sync-user.ts` so the first dashboard visit upserts a Prisma user for Stripe `metadata.userId`. Environment variables are Clerk keys plus optional `NEXT_PUBLIC_CLERK_SIGN_*` URL hints (see template `.env.example`).+## [2.1.3] — 2026-05-03Patch release — `bin/ops-external` and `bin/ops-marketing-dash` are now preferences-aware and surface real Shopify, Klaviyo, Meta, Instagram, and GSC data per project. `/ops:ops-yolo` always archives prior session reports to force a fresh-state run.diff --git a/claude-ops/templates/nextjs-saas/.env.example b/claude-ops/templates/nextjs-saas/.env.exampleindex b92708e8..f7e3bc1c 100644--- a/claude-ops/templates/nextjs-saas/.env.example+++ b/claude-ops/templates/nextjs-saas/.env.example@@ -1,9 +1,9 @@DATABASE_URL=postgresql://postgres:postgres@localhost:5432/saasapp-NEXTAUTH_URL=http://localhost:3000-NEXTAUTH_SECRET=change-me-to-random-secret-32-chars-min-GITHUB_CLIENT_ID=your-github-oauth-app-client-id-GITHUB_CLIENT_SECRET=your-github-oauth-app-client-secret-GOOGLE_CLIENT_ID=your-google-oauth-client-id-GOOGLE_CLIENT_SECRET=your-google-oauth-client-secret+NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_your-clerk-publishable-key+CLERK_SECRET_KEY=sk_test_your-clerk-secret-key+NEXT_PUBLIC_CLERK_SIGN_IN_URL=/login+NEXT_PUBLIC_CLERK_SIGN_UP_URL=/register+NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL=/dashboard+NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL=/dashboardSTRIPE_SECRET_KEY=sk_test_your-stripe-secret-keySTRIPE_WEBHOOK_SECRET=whsec_your-stripe-webhook-secretdiff --git a/claude-ops/templates/nextjs-saas/README.md b/claude-ops/templates/nextjs-saas/README.mdindex 8a39287d..916802a2 100644--- a/claude-ops/templates/nextjs-saas/README.md+++ b/claude-ops/templates/nextjs-saas/README.md@@ -1,13 +1,13 @@# Next.js SaaS Template-Production-ready SaaS starter with Next.js 14 App Router, Auth.js v5, Stripe billing, Prisma ORM, and Tailwind CSS.+Production-ready SaaS starter with Next.js App Router, Clerk authentication, Stripe billing, Prisma ORM, and Tailwind CSS.## Features-- **Next.js 14 App Router** — server components, layouts, route groups-- **Auth.js v5 (next-auth@beta)** — GitHub and Google OAuth, PrismaAdapter, server-side sessions-- **Stripe billing** — subscription webhook handler with signature verification-- **Prisma ORM** — PostgreSQL with User, Account, Session, Subscription, VerificationToken models+- **Next.js App Router** — server components, layouts, route groups+- **Clerk** — hosted sign-in/sign-up, `clerkMiddleware` route protection, `UserButton` in the dashboard shell+- **Prisma** — PostgreSQL with `User` (linked to Clerk via `clerkUserId`) and `Subscription` models+- **Stripe billing** — subscription webhook handler with signature verification (`metadata.userId` = Prisma `User.id`)- **Tailwind CSS v3** — utility-first styling, responsive dashboard layout- **Landing page** — hero section with CTA buttons- **Dashboard layout** — sidebar navigation, metric cards@@ -16,8 +16,8 @@ Production-ready SaaS starter with Next.js 14 App Router, Auth.js v5, Stripe bil- Node 20+- PostgreSQL (local or hosted)+- [Clerk](https://clerk.com) application (API keys)- Stripe account (for billing features)-- GitHub OAuth App and/or Google OAuth credentials## Quick Start@@ -39,30 +39,23 @@ The app will be available at `http://localhost:3000`.## Environment Variables-| Variable | Description |-| ------------------------ | ------------------------------------------------- |-| `DATABASE_URL` | PostgreSQL connection string |-| `NEXTAUTH_URL` | Full URL of your app (e.g. `http://localhost:3000`) |-| `NEXTAUTH_SECRET` | Random 32+ char secret for session signing |-| `GITHUB_CLIENT_ID` | GitHub OAuth App client ID |-| `GITHUB_CLIENT_SECRET` | GitHub OAuth App client secret |-| `GOOGLE_CLIENT_ID` | Google OAuth client ID |-| `GOOGLE_CLIENT_SECRET` | Google OAuth client secret |-| `STRIPE_SECRET_KEY` | Stripe secret key (`sk_test_...` or `sk_live_...`) |-| `STRIPE_WEBHOOK_SECRET` | Stripe webhook signing secret (`whsec_...`) |--## Auth Provider Setup--### GitHub OAuth-1. Go to GitHub → Settings → Developer Settings → OAuth Apps → New OAuth App-2. Set **Authorization callback URL** to `http://localhost:3000/api/auth/callback/github`-3. Copy Client ID and Client Secret to `.env`--### Google OAuth-1. Go to [Google Cloud Console](https://console.cloud.google.com) → APIs & Services → Credentials-2. Create OAuth 2.0 Client ID (Web application)-3. Add `http://localhost:3000/api/auth/callback/google` as an authorized redirect URI-4. Copy Client ID and Client Secret to `.env`+| Variable | Description |+| -------- | ----------- |+| `DATABASE_URL` | PostgreSQL connection string |+| `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` | Clerk publishable key (`pk_test_...` / `pk_live_...`) |+| `CLERK_SECRET_KEY` | Clerk secret key (`sk_test_...` / `sk_live_...`) |+| `NEXT_PUBLIC_CLERK_SIGN_IN_URL` | Path hosting `<SignIn />` (default `/login`) |+| `NEXT_PUBLIC_CLERK_SIGN_UP_URL` | Path hosting `<SignUp />` (default `/register`) |+| `NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL` | Post sign-in redirect when none is specified |+| `NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL` | Post sign-up redirect when none is specified |+| `STRIPE_SECRET_KEY` | Stripe secret key (`sk_test_...` or `sk_live_...`) |+| `STRIPE_WEBHOOK_SECRET` | Stripe webhook signing secret (`whsec_...`) |++Create a Clerk application at [dashboard.clerk.com](https://dashboard.clerk.com), copy the keys into `.env`, and add `http://localhost:3000` to allowed origins / redirect URLs as prompted in the Clerk dashboard.++## Clerk + Stripe++The dashboard calls `syncClerkUser()` on first load so a Prisma `User` row exists before Stripe webhooks attach subscriptions. When creating Stripe Checkout sessions, set `metadata: { userId: '<prisma User.id>' }` so the webhook in `app/api/webhooks/stripe/route.ts` can link rows correctly.## Stripe Webhook Setup@@ -82,14 +75,11 @@ The app will be available at `http://localhost:3000`.1. Push your repo to GitHub2. Import the project in Vercel-3. Add all environment variables in the Vercel dashboard-4. Set `NEXTAUTH_URL` to your production domain-5. Deploy+3. Add all environment variables in the Vercel dashboard (including Clerk keys and sign-in URL envs)+4. Deploy### Other platforms-Build the app and run it:-```bashnpm run buildnpm startdiff --git a/claude-ops/templates/nextjs-saas/app/(auth)/login/[[...rest]]/page.tsx b/claude-ops/templates/nextjs-saas/app/(auth)/login/[[...rest]]/page.tsxnew file mode 100644index 00000000..2c7979c6--- /dev/null+++ b/claude-ops/templates/nextjs-saas/app/(auth)/login/[[...rest]]/page.tsx@@ -0,0 +1,9 @@+import { SignIn } from '@clerk/nextjs'++export default function LoginPage() {+ return (+ <div className="flex min-h-screen items-center justify-center bg-gray-50">+ <SignIn routing="path" path="/login" signUpUrl="/register" forceRedirectUrl="/dashboard" />+ </div>+ )+}diff --git a/claude-ops/templates/nextjs-saas/app/(auth)/login/page.tsx b/claude-ops/templates/nextjs-saas/app/(auth)/login/page.tsxdeleted file mode 100644index a0fd9783..00000000--- a/claude-ops/templates/nextjs-saas/app/(auth)/login/page.tsx+++ /dev/null@@ -1,24 +0,0 @@-'use client';-import { signIn } from 'next-auth/react';--export default function LoginPage() {- return (- <div className="flex min-h-screen items-center justify-center bg-gray-50">- <div className="w-full max-w-md rounded-lg bg-white p-8 shadow">- <h2 className="text-2xl font-bold text-gray-900">Sign in</h2>- <button- onClick={() => signIn('github', { callbackUrl: '/dashboard' })}- className="mt-6 w-full rounded-md bg-gray-900 px-4 py-2 text-white hover:bg-gray-700"- >- Continue with GitHub- </button>- <button- onClick={() => signIn('google', { callbackUrl: '/dashboard' })}- className="mt-3 w-full rounded-md border border-gray-300 px-4 py-2 hover:bg-gray-50"- >- Continue with Google- </button>- </div>- </div>- );-}diff --git a/claude-ops/templates/nextjs-saas/app/(auth)/register/[[...rest]]/page.tsx b/claude-ops/templates/nextjs-saas/app/(auth)/register/[[...rest]]/page.tsxnew file mode 100644index 00000000..f607a9ea--- /dev/null+++ b/claude-ops/templates/nextjs-saas/app/(auth)/register/[[...rest]]/page.tsx@@ -0,0 +1,9 @@+import { SignUp } from '@clerk/nextjs'++export default function RegisterPage() {+ return (+ <div className="flex min-h-screen items-center justify-center bg-gray-50">+ <SignUp routing="path" path="/register" signInUrl="/login" forceRedirectUrl="/dashboard" />+ </div>+ )+}diff --git a/claude-ops/templates/nextjs-saas/app/(dashboard)/layout.tsx b/claude-ops/templates/nextjs-saas/app/(dashboard)/layout.tsxindex 29354a61..c9b50b1a 100644--- a/claude-ops/templates/nextjs-saas/app/(dashboard)/layout.tsx+++ b/claude-ops/templates/nextjs-saas/app/(dashboard)/layout.tsx@@ -1,11 +1,13 @@-import Link from 'next/link';+import Link from 'next/link'+import { UserButton } from '@clerk/nextjs'export default function DashboardLayout({ children }: { children: React.ReactNode }) {return (<div className="flex h-screen bg-gray-100"><aside className="w-64 bg-white shadow-sm">- <div className="p-6">+ <div className="flex items-center justify-between p-6"><h2 className="text-xl font-semibold">SaaS App</h2>+ <UserButton afterSignOutUrl="/" /></div><nav className="mt-4 px-4"><Link@@ -24,5 +26,5 @@ export default function DashboardLayout({ children }: { children: React.ReactNod</aside><main className="flex-1 overflow-auto p-8">{children}</main></div>- );+ )}diff --git a/claude-ops/templates/nextjs-saas/app/(dashboard)/page.tsx b/claude-ops/templates/nextjs-saas/app/(dashboard)/page.tsxindex 9f7499af..da6ad580 100644--- a/claude-ops/templates/nextjs-saas/app/(dashboard)/page.tsx+++ b/claude-ops/templates/nextjs-saas/app/(dashboard)/page.tsx@@ -1,8 +1,14 @@-export default function DashboardPage() {+import { syncClerkUser } from '../../../lib/sync-user'++export default async function DashboardPage() {+ const user = await syncClerkUser()+return (<div><h1 className="text-3xl font-bold text-gray-900">Dashboard</h1>- <p className="mt-2 text-gray-600">Welcome back. Here is your overview.</p>+ <p className="mt-2 text-gray-600">+ Welcome back{user?.name ? `, ${user.name}` : ''}. Here is your overview.+ </p><div className="mt-6 grid grid-cols-1 gap-6 sm:grid-cols-3">{['Total Users', 'Monthly Revenue', 'Active Subscriptions'].map((metric) => (<div key={metric} className="rounded-lg bg-white p-6 shadow">@@ -12,5 +18,5 @@ export default function DashboardPage() {))}</div></div>- );+ )}diff --git a/claude-ops/templates/nextjs-saas/app/api/auth/[...nextauth]/route.ts b/claude-ops/templates/nextjs-saas/app/api/auth/[...nextauth]/route.tsdeleted file mode 100644index 3bc7e225..00000000--- a/claude-ops/templates/nextjs-saas/app/api/auth/[...nextauth]/route.ts+++ /dev/null@@ -1,2 +0,0 @@-import { handlers } from '../../../../lib/auth';-export const { GET, POST } = handlers;diff --git a/claude-ops/templates/nextjs-saas/app/layout.tsx b/claude-ops/templates/nextjs-saas/app/layout.tsxindex 9c7cf8e0..5abdf371 100644--- a/claude-ops/templates/nextjs-saas/app/layout.tsx+++ b/claude-ops/templates/nextjs-saas/app/layout.tsx@@ -1,18 +1,21 @@-import type { Metadata } from 'next';-import { Inter } from 'next/font/google';-import './globals.css';+import type { Metadata } from 'next'+import { Inter } from 'next/font/google'+import { ClerkProvider } from '@clerk/nextjs'+import './globals.css'-const inter = Inter({ subsets: ['latin'] });+const inter = Inter({ subsets: ['latin'] })export const metadata: Metadata = {title: 'SaaS App',description: 'Built with Next.js App Router',-};+}export default function RootLayout({ children }: { children: React.ReactNode }) {return (<html lang="en">- <body className={inter.className}>{children}</body>+ <body className={inter.className}>+ <ClerkProvider>{children}</ClerkProvider>+ </body></html>- );+ )}diff --git a/claude-ops/templates/nextjs-saas/lib/auth.ts b/claude-ops/templates/nextjs-saas/lib/auth.tsdeleted file mode 100644index cd934925..00000000--- a/claude-ops/templates/nextjs-saas/lib/auth.ts+++ /dev/null@@ -1,26 +0,0 @@-import NextAuth from 'next-auth';-import GitHub from 'next-auth/providers/github';-import Google from 'next-auth/providers/google';-import { PrismaAdapter } from '@auth/prisma-adapter';-import { prisma } from './prisma';--export const { handlers, auth, signIn, signOut } = NextAuth({- adapter: PrismaAdapter(prisma),- providers: [- GitHub({- clientId: process.env.GITHUB_CLIENT_ID!,- clientSecret: process.env.GITHUB_CLIENT_SECRET!,- }),- Google({- clientId: process.env.GOOGLE_CLIENT_ID!,- clientSecret: process.env.GOOGLE_CLIENT_SECRET!,- }),- ],- pages: { signIn: '/login' },- callbacks: {- session({ session, user }) {- session.user.id = user.id;- return session;- },- },-});diff --git a/claude-ops/templates/nextjs-saas/lib/sync-user.ts b/claude-ops/templates/nextjs-saas/lib/sync-user.tsnew file mode 100644index 00000000..353a38a6--- /dev/null+++ b/claude-ops/templates/nextjs-saas/lib/sync-user.ts@@ -0,0 +1,41 @@+import { auth, currentUser } from '@clerk/nextjs/server'+import { prisma } from './prisma'++/** Ensures a Prisma User row exists for the signed-in Clerk user (used for Stripe metadata.userId). */+export async function syncClerkUser() {+ const { userId } = await auth()+ if (!userId) {+ return null+ }++ const clerkUser = await currentUser()+ if (!clerkUser) {+ return null+ }++ const primaryEmail =+ clerkUser.emailAddresses.find((e) => e.id === clerkUser.primaryEmailAddressId)?.emailAddress ??+ clerkUser.emailAddresses[0]?.emailAddress++ if (!primaryEmail) {+ return null+ }++ const nameFromParts = [clerkUser.firstName, clerkUser.lastName].filter(Boolean).join(' ')+ const name = clerkUser.fullName ?? (nameFromParts || null)++ return prisma.user.upsert({+ where: { clerkUserId: userId },+ update: {+ email: primaryEmail,+ name,+ image: clerkUser.imageUrl ?? null,+ },+ create: {+ clerkUserId: userId,+ email: primaryEmail,+ name,+ image: clerkUser.imageUrl ?? null,+ },+ })+}diff --git a/claude-ops/templates/nextjs-saas/middleware.ts b/claude-ops/templates/nextjs-saas/middleware.tsnew file mode 100644index 00000000..492875ee--- /dev/null+++ b/claude-ops/templates/nextjs-saas/middleware.ts@@ -0,0 +1,21 @@+import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'++const isPublicRoute = createRouteMatcher([+ '/',+ '/login(.*)',+ '/register(.*)',+ '/api/webhooks(.*)',+])++export default clerkMiddleware(async (auth, req) => {+ if (!isPublicRoute(req)) {+ await auth.protect()+ }+})++export const config = {+ matcher: [+ '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',+ '/(api|trpc)(.*)',+ ],+}diff --git a/claude-ops/templates/nextjs-saas/package.json b/claude-ops/templates/nextjs-saas/package.jsonindex e57e993e..3c342230 100644--- a/claude-ops/templates/nextjs-saas/package.json+++ b/claude-ops/templates/nextjs-saas/package.json@@ -11,11 +11,10 @@"db:studio": "prisma studio"},"dependencies": {+ "@clerk/nextjs": "^6.36.5","next": "^16.2.3","react": "^18.0.0","react-dom": "^18.0.0",- "next-auth": "^5.0.0-beta.25",- "@auth/prisma-adapter": "^2.0.0","@prisma/client": "^5.0.0","stripe": "^14.0.0","clsx": "^2.0.0",diff --git a/claude-ops/templates/nextjs-saas/prisma/schema.prisma b/claude-ops/templates/nextjs-saas/prisma/schema.prismaindex 70d4176e..1a33375e 100644--- a/claude-ops/templates/nextjs-saas/prisma/schema.prisma+++ b/claude-ops/templates/nextjs-saas/prisma/schema.prisma@@ -9,42 +9,15 @@ datasource db {model User {id String @id @default(cuid())+ clerkUserId String @uniquename String?email String @uniqueemailVerified DateTime?image String?- accounts Account[]- sessions Session[]subscriptions Subscription[]createdAt DateTime @default(now())}-model Account {- id String @id @default(cuid())- userId String- type String- provider String- providerAccountId String- refresh_token String?- access_token String?- expires_at Int?- token_type String?- scope String?- id_token String?- session_state String?- user User @relation(fields: [userId], references: [id], onDelete: Cascade)-- @@unique([provider, providerAccountId])-}--model Session {- id String @id @default(cuid())- sessionToken String @unique- userId String- expires DateTime- user User @relation(fields: [userId], references: [id], onDelete: Cascade)-}-model Subscription {id String @id @default(cuid())userId String@@ -52,13 +25,5 @@ model Subscription {status StringcreatedAt DateTime @default(now())updatedAt DateTime @updatedAt- user User @relation(fields: [userId], references: [id])-}--model VerificationToken {- identifier String- token String @unique- expires DateTime-- @@unique([identifier, token])+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)}