Add auth
Add NextAuth (Auth.js) authentication to an existing T3 project. One structured question decides the mode - admin (fixed login in env vars) or users (DB-backed email+password with signup, signin, account page, delete account, and optional forgot-password if email is configured). Credentials-only - no OAuth providers. This skill is an orchestrator - it delegates the actual implementation to `_setup-auth-admin` or `_setup-auth-users` depending on the chosen mode.From its SKILL.md
npx -y skills add calopsys/baudrier --skill add-authAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
10.5 KB, as published. Nobody here has run it
Add Auth - Orchestrator
Communication
- 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.
- Use plain, non-technical business language. Never expose internal script names (*.mjs) or jargon; describe actions in human terms.
- When generating user-facing content for the scaffolded project (UI labels, emails, copy), write it in the user's language too.
- Show progress as a short natural-language checklist (in-progress and done states).
Lightweight orchestrator. Detects the current state via the // baudrier: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.
Step 0 - Detect the current state and contextual menu
Garde vitrine : invoke _detect-project-root first. If PROJECT_TYPE=landing, stop and tell the user, in their language (French shown): « Cette fonctionnalité n’est pas disponible pour un site vitrine : elle est réservée aux applications web. Votre site reste modifiable, et vous pouvez le déployer avec /deploy. »
Read the marker in src/server/auth.ts:
if [ -f "<WEB_DIR>/src/server/auth.ts" ]; then
grep -E "^// baudrier:auth-modes" "<WEB_DIR>/src/server/auth.ts" | head -1
fi
Parse:
- No file OR no marker →
existing_modes = [] // baudrier:auth-modes admin→["admin"]// baudrier:auth-modes users→["users"]// baudrier:auth-modes admin, users→["admin","users"]auth.tspresent WITHOUT marker →["unknown"]
Case [] → fresh install
No menu. Skip to Step 1.
Case ["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 --env production, show the password= ONCE to the user. |
| 3 | List the files to delete manually, then ask to re-run. |
| 4 | Ask for clarification. |
Case ["users"] → menu
🔐 User signup is already in place
- Also add a separate admin login
- Enable password reset (forgot-password - only if email is configured)
- Start over from scratch
- Something else
| Choice | Action |
|---|---|
| 1 | UPGRADE Section - Case B. |
| 2 | _check-deps email ; if OK, UPGRADE Section - Case C. Otherwise point to /add-email. |
| 3 | List the files to delete (auth.ts, password.ts, auth router, /signin /signup /dashboard /account pages, NextAuth tables in the DB). |
| 4 | Ask for clarification. |
Case ["admin","users"] → menu
🔐 You have BOTH modes (admin + users)
- Change the admin password (same as admin case choice 2)
- Enable password reset (same as users case choice 2)
- Uninstall a mode - destructive, ask for explicit confirmation and guide manually
- Something else
Case ["unknown"] → pre-existing auth not recognized
⚠️ You already have a
src/server/auth.tsbut I do not recognize its origin (no baudrier 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.
Step 1 - Choose the mode (fresh install only)
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 only option when there are users? It is the only 0-config system that works everywhere and needs no third-party account. This harness does not offer OAuth sign-in providers.
Step 2 - Prerequisites (fresh install only)
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.
Step 3 - Delegate to the sub-skill (fresh install)
auth_mode = admin-credentials→ invoke_setup-auth-adminwithWEB_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.
UPGRADE Section - Add a mode (Claude drives, no script)
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.
Case A - Add users on top of an existing admin
Reference 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).- Build the hybrid
auth.ts: marker →// baudrier:auth-modes admin, users. ImportDrizzleAdapter, schema tables,eq,db. Module augmentationSession.user.id.authorize(): admin path FIRST (checkemail === ADMIN_USERNAME,getAdminPasswordHash), users path as FALLBACK (db.query.users.findFirst→verifyPassword). KeepisAdmin(). Add jwt/session callbacks. - Extend
password.ts: addhashPassword()(from the users template). KeepgetAdminPasswordHash+verifyPassword. - Patch schema.ts - like
setup-auth-users.mjsdoes in thepatchSchemastep: add the missing imports (pgTable, text, integer, primaryKey, index, timestamppg-core,sqldrizzle-orm,AdapterAccounttype next-auth/adapters), append the 4 NextAuth tables (+password_reset_tokensif email_ok). pnpm db:generate(writes the SQL migration, no DB connection; the next/deployapplies it).- Patch trpc.ts - add
protectedProcedure(andrateLimitedProcedureif missing). Take inspiration from thesetup-auth-users.mjsaddProtectedProcedurestep. - Create
src/server/api/routers/auth.tsfrom the right template (auth-router.tsorauth-router-with-reset.ts). - Register in
root.ts: import +auth: authRouter,. - Create
src/app/api/auth/[...nextauth]/route.tsfrom the template (admin and users are identical). - Create the 4 users pages: signin (with
FORGOT_PASSWORD_LINKsubstituted), signup, dashboard, account (+ forgot/reset if email_ok). - Patch
layout.tsxfor the user-menu (best-effort, like_setup-auth-usersStep 2). - Update CLAUDE.md - add the users sections in addition to the admin sections already present.
pnpm tsc --noEmit- check that it compiles.- Summary: "User signup has been added on top of the admin login. The admin login keeps working and has priority in the authorize callback." Remind the user that a
/deployis needed before the new tables exist and signup works.
Case B - Add admin on top of an existing users
Reference templates: templates/auth/admin/{auth.ts, password.ts} (for the snippets to integrate).
- Hash passwords: DEV via stdin (
printf '%s' "Admin1234!" | node "<path>/hash-password.mjs"), PROD via--generate --length 24 --format alphanumeric. Capturepassword=andhash=. - Push env vars:
_push-env-vars --env production ADMIN_USERNAME=admin ADMIN_PASSWORD_HASH_DEV=<dev> ADMIN_PASSWORD_HASH_PROD=<prod>. - Extend
password.ts- addgetAdminPasswordHash()from the admin template. KeephashPassword+verifyPassword. - Patch
auth.ts: marker →// baudrier:auth-modes admin, users. ImportgetAdminPasswordHashfrom~/lib/password. Inauthorize(), BEFORE the DB lookup, add the admin path:
Addif (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; }export async function isAdmin() { return (await auth())?.user?.id === "admin"; }. - Update CLAUDE.md - add the admin section in addition to the users sections.
pnpm tsc --noEmit- check.- Summary: show the PROD password ONCE (never on disk), explain the coexistence in authorize.
Case C - Enable password reset on an existing users (email already OK)
- Append
password_reset_tokensto schema.ts fromtemplates/auth/users/schema-additions-reset-tokens.ts. pnpm db:generate(writes the SQL migration, no DB connection; the next/deployapplies it).- Replace
src/server/api/routers/auth.tswith theauth-router-with-reset.tstemplate (sends via Scaleway Transactional Email). - Create
/forgot-password/page.tsxand/reset-password/page.tsxfrom the templates. - Patch signin.tsx: replace
<span></span>(placeholder forFORGOT_PASSWORD_LINK) with the<Link href="/forgot-password" ...>Forgot password?</Link>. - Update CLAUDE.md - add the reset mention.
pnpm tsc --noEmit+ summary. Remind the user that a/deployis needed before the password-reset table exists and the flow works.