From hypervibe
Adds NextAuth (Auth.js) authentication to an existing T3 project with admin or user mode, including email/password signup, account management, and optional OAuth providers.
How this skill is triggered — by the user, by Claude, or both
Slash command
/hypervibe:add-auth [mode: admin | users][mode: admin | users]The summary Claude sees in its skill listing — used to decide when to auto-load this skill
- Detect the user's language from their messages and ALWAYS reply in that language (default: English). This applies to every user-facing message: questions, progress, confirmations, summaries, errors.
Lightweight orchestrator. Detects the current state via the // hypervibe:auth-modes <list> marker at the top of src/server/auth.ts, proposes a contextual menu based on what is already installed, and delegates to the right sub-skill (_setup-auth-admin / _setup-auth-users) for fresh installs. For UPGRADES (adding the second mode when one already exists), Claude drives the contextual editing of auth.ts itself - see the UPGRADE Section.
Read the marker in src/server/auth.ts:
if [ -f "<WEB_DIR>/src/server/auth.ts" ]; then
grep -E "^// hypervibe:auth-modes" "<WEB_DIR>/src/server/auth.ts" | head -1
fi
Parse:
existing_modes = []// hypervibe:auth-modes admin → ["admin"]// hypervibe:auth-modes users → ["users"]// hypervibe:auth-modes admin, users → ["admin","users"]auth.ts present WITHOUT marker → ["unknown"][] → fresh installNo menu. Skip to Step 1.
["admin"] → menu🔐 The admin login is already in place
- Also add a signup system for my users (both coexist)
- Change the admin password
- Start over from scratch (deletes auth.ts/password.ts/route.ts + AUTH_SECRET/ADMIN_* first)
- Something else
| Choice | Action |
|---|---|
| 1 | UPGRADE Section - Case A. |
| 2 | node "${CLAUDE_SKILL_DIR}/../../scripts/hash-password.mjs" --generate --length 24 --format alphanumeric → push ADMIN_PASSWORD_HASH_PROD via _push-env-vars --target=production,preview, show the password= ONCE to the user. |
| 3 | List the files to delete manually, then ask to re-run. |
| 4 | Ask for clarification. |
["users"] → menu🔐 User signup is already in place
- Also add a separate admin login
- Add a Google sign-in
- Add a GitHub sign-in
- Enable password reset (forgot-password - only if email is configured)
- Start over from scratch
- Something else
| Choice | Action |
|---|---|
| 1 | UPGRADE Section - Case B. |
| 2 | Invoke add-google-auth. |
| 3 | Invoke add-github-auth. |
| 4 | _check-deps email ; if OK, UPGRADE Section - Case C. Otherwise point to /add-email. |
| 5 | List the files to delete (auth.ts, password.ts, auth router, /signin /signup /dashboard /account pages, NextAuth tables in the DB). |
| 6 | Ask for clarification. |
["admin","users"] → menu🔐 You have BOTH modes (admin + users)
- Change the admin password (same as admin case choice 2)
- Add Google (same as users case choice 2)
- Add GitHub (same as users case choice 3)
- Enable password reset (same as users case choice 4)
- Uninstall a mode - destructive, ask for explicit confirmation and guide manually
- Something else
["unknown"] → pre-existing auth not recognized⚠️ You already have a
src/server/auth.tsbut I do not recognize its origin (no hypervibe marker). Three options: (1) you tell me what you want to do and I guide you manually; (2) you confirm that I can overwrite and start over; (3) we stop.
If called from /bootstrap, the mode is already chosen → skip to Step 2. If standalone with an explicit arg (admin / users), use it. Otherwise AskUserQuestion:
What type of authentication does your project need?
- Just a protected admin interface (only you log in - content management, site admin)
- A system for your users (visitors create an account and sign in)
→ auth_mode = admin-credentials or user-credentials.
Why is email+pwd the baseline when there are users? It is the only 0-config system that works everywhere. OAuth (Google, GitHub) is a convenience added on top, never a replacement.
Invoke _detect-project-root → PROJECT_NAME, WEB_DIR, IS_MONOREPO, IS_NEXTJS. Abort if not Next.js.
If auth_mode = user-credentials: _check-deps db → if db_ok = false, propose /add-db then re-check.
auth_mode = admin-credentials → invoke _setup-auth-admin with WEB_DIR, IS_MONOREPO, PROJECT_NAME.auth_mode = user-credentials → invoke _setup-auth-users.The sub-skill handles the script + UserMenu (users mode) + CLAUDE.md + summary. When it hands control back, you are done - the orchestrator has nothing to add.
No script - the risk of corrupting the existing auth.ts is too high. Claude reads the existing file, reads the reference templates in templates/auth/, and patches contextually. Check pnpm tsc --noEmit at the end to validate.
users on top of an existing adminReference templates: templates/auth/users/{auth.ts, password.ts, schema-additions.ts, schema-additions-reset-tokens.ts, auth-router*.ts, route.ts}.
Steps (all driven by Claude):
_check-deps db (DB required) ; _check-deps email (optional for reset).auth.ts: marker → // hypervibe:auth-modes admin, users. Import DrizzleAdapter, schema tables, eq, db. Module augmentation Session.user.id. authorize(): admin path FIRST (check email === ADMIN_USERNAME, getAdminPasswordHash), users path as FALLBACK (db.query.users.findFirst → verifyPassword). Keep isAdmin(). Add jwt/session callbacks.password.ts: add hashPassword() (from the users template). Keep getAdminPasswordHash + verifyPassword.setup-auth-users.mjs does in the patchSchema step: add the missing imports (text, integer, primaryKey, index, timestamp pg-core, sql drizzle-orm, AdapterAccount type next-auth/adapters), append the 4 NextAuth tables (+ password_reset_tokens if email_ok).pnpm db:push (or --force).protectedProcedure (and rateLimitedProcedure if missing). Take inspiration from the setup-auth-users.mjs addProtectedProcedure step.src/server/api/routers/auth.ts from the right template (auth-router.ts or auth-router-with-reset-{provider}.ts).root.ts: import + auth: authRouter,.src/app/api/auth/[...nextauth]/route.ts from the template (admin and users are identical).FORGOT_PASSWORD_LINK substituted), signup, dashboard, account (+ forgot/reset if email_ok).layout.tsx for the user-menu (best-effort, like _setup-auth-users Step 2).pnpm tsc --noEmit - check that it compiles.admin on top of an existing usersReference templates: templates/auth/admin/{auth.ts, password.ts} (for the snippets to integrate).
printf '%s' "Admin1234!" | node "<path>/hash-password.mjs"), PROD via --generate --length 24 --format alphanumeric. Capture password= and hash=._push-env-vars --target=all ADMIN_USERNAME=admin ADMIN_PASSWORD_HASH_DEV=<dev> ADMIN_PASSWORD_HASH_PROD=<prod>.password.ts - add getAdminPasswordHash() from the admin template. Keep hashPassword + verifyPassword.auth.ts: marker → // hypervibe:auth-modes admin, users. Import getAdminPasswordHash from ~/lib/password. In authorize(), BEFORE the DB lookup, add the admin path:
if (process.env.ADMIN_USERNAME && email === process.env.ADMIN_USERNAME) {
const hash = getAdminPasswordHash();
if (await verifyPassword(password, hash)) return { id: "admin", email, name: "Admin" };
return null;
}
Add export async function isAdmin() { return (await auth())?.user?.id === "admin"; }.pnpm tsc --noEmit - check.users (email already OK)password_reset_tokens to schema.ts from templates/auth/users/schema-additions-reset-tokens.ts.pnpm db:push.src/server/api/routers/auth.ts with the auth-router-with-reset-{resend,brevo}.ts template (depending on the detected provider)./forgot-password/page.tsx and /reset-password/page.tsx from the templates.<span></span> (placeholder for FORGOT_PASSWORD_LINK) with the <Link href="/forgot-password" ...>Forgot password?</Link>.pnpm tsc --noEmit + summary.npx claudepluginhub flavien-ia/hypervibe-harness --plugin hypervibeSets up NextAuth user-credentials mode with DB-backed email/password auth, signup/signin, account page with delete, and optional forgot/reset password. Invoked by add-auth.
Scaffold signin and signup authentication endpoints for a project. Use when the user wants to add authentication, create login/register flows, or set up auth from scratch.
Sets up Neon Auth in Next.js, React SPA, or Node.js apps. Configures auth routes, session management, social providers, and generates UI components.