auth-module-builder — Claude Code skill: login, JWT, sessions
auth-module-builder lays out a full authentication module: login and registration routes, JWT signing, bcrypt hashing, Redis sessions and a threat model. Useful when the login flow starts from an empty file.
MIT 263 installs ★ 64 updated 2026-01-12
npx skills add patricio0312rev/skills --skill auth-module-builder -a claude-codeWhat auth-module-builder does
The skill maps the pieces of an auth module: routes for POST /login, /register, /logout, /refresh and /forgot-password, plus authenticate, requireAuth and optionalAuth middleware. Token verification pulls the value from the Authorization header and then loads the user by the id stored in the payload. Code samples are TypeScript, with a 15-minute access token and a 7-day refresh token.
Sessions have their own pattern: express-session on a Redis store, httpOnly cookies, sameSite: lax, and the secure flag turned on in production. A checklist and a threat model sit alongside — brute force, token theft, CSRF, session fixation, XSS, each paired with a mitigation.
Three secrets come from the environment: JWT_SECRET, JWT_REFRESH_SECRET, SESSION_SECRET. Set them before asking an agent to wire anything up, since the signing and session code reads only from there. The checklist puts the bcrypt cost floor at 10, and the sample sits exactly on that number — a lower value fails the check.
What it helps with
- scaffold login and registration with hashed passwords
- issue access and refresh tokens with separate lifetimes
- keep sessions in Redis behind httpOnly cookies
- block brute force and CSRF on the auth routes
- hand reviewers a threat model for the login flow
Example prompts for the agent
- Build the auth module: login, registration, logout and token refresh routes
- Add
requireAuthmiddleware that checks the JWT from theAuthorizationheader - Set up Redis-backed sessions with httpOnly cookies and CSRF protection
How to install auth-module-builder
1Skills CLI (Vercel)
npx skills add patricio0312rev/skills --skill auth-module-builder -a claude-code2Manually: put the files in place
~/.claude/skills/auth-module-builder/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/auth-module-builder/
1Skills CLI (Vercel)
npx skills add patricio0312rev/skills --skill auth-module-builder -a codex2Manually: put the files in place
.agents/skills/auth-module-builder/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add patricio0312rev/skills --skill auth-module-builder -a cursor2Manually: put the files in place
.cursor/skills/auth-module-builder/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install patricio0312rev/skills backend/auth-module-builder/SKILL.md2Manually: put the files in place
.github/skills/auth-module-builder/SKILL.md1Skills CLI (Vercel)
npx skills add patricio0312rev/skills --skill auth-module-builder -a gemini-cli2Platform CLI
gemini skills install https://github.com/patricio0312rev/skills --path backend/auth-module-builderManually: put the files in place
.devin/skills/auth-module-builder/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add patricio0312rev/skills --skill auth-module-builder -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about auth-module-builder
How do I install auth-module-builder in Claude Code?
Run npx skills add patricio0312rev/skills --skill auth-module-builder -a claude-code. The skill lands in ~/.claude/skills/auth-module-builder/SKILL.md.
What does auth-module-builder do?
It describes login, registration and password-reset routes, JWT middleware, bcrypt hashing, cookie settings and CSRF handling. It also ships a security checklist and a write-up of common attacks with mitigations.
Which environment variables does it need?
JWT_SECRET and JWT_REFRESH_SECRET for signing tokens, SESSION_SECRET for sessions. All three are read from the environment rather than hardcoded.
Source text
SKILL.md · MIT
---
name: auth-module-builder
description: Implements secure authentication patterns including login/registration, session management, JWT tokens, password hashing, cookie settings, and CSRF protection. Provides auth routes, middleware, security configurations, and threat model documentation. Use when building "authentication", "login system", "JWT auth", or "session management".
---
# Auth Module Builder
Implement secure, production-ready authentication systems.
## Core Components
**Routes**: POST /login, /register, /logout, /refresh, /forgot-password
**Middleware**: authenticate, requireAuth, optionalAuth
**Security**: bcrypt hashing, JWT signing, secure cookies, CSRF tokens
**Session**: Redis/DB storage, expiration, refresh tokens
**Threats**: Document common attacks and mitigations
## JWT Pattern
```typescript
// Generate tokens
const accessToken = jwt.sign(
{ userId: user.id, email: user.email },
process.env.JWT_SECRET,
{ expiresIn: "15m" }
);
const refreshToken = jwt.sign(
{ userId: user.id, type: "refresh" },
process.env.JWT_REFRESH_SECRET,
{ expiresIn: "7d" }
);
// Verify middleware
export const authenticate = async (req, res, next) => {
const token = req.headers.authorization?.split(" ")[1];
if (!token) return res.status(401).json({ error: "No token" });
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = await User.findById(decoded.userId);
next();
} catch (err) {
res.status(401).json({ error: "Invalid token" });
}
};
```
## Session Pattern
```typescript
// Express session with Redis
app.use(
session({
store: new RedisStore({ client: redisClient }),
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
secure: process.env.NODE_ENV === "production",
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 7, // 7 days
sameSite: "lax",
},
})
);
```
## Password Security
```typescript
import bcrypt from "bcrypt";
// Hash password
const hashedPassword = await bcrypt.hash(password, 10);
// Verify password
const isValid = await bcrypt.compare(password, user.hashedPassword);
```
## Security Checklist
- [ ] Passwords hashed with bcrypt (cost ≥10)
- [ ] JWT secrets from environment, rotated regularly
- [ ] HTTPS only in production
- [ ] httpOnly, secure cookies
- [ ] CSRF protection enabled
- [ ] Rate limiting on auth routes
- [ ] Account lockout after failed attempts
- [ ] Password reset tokens expire
- [ ] Email verification for new accounts
## Threat Model
**Brute Force**: Rate limit + account lockout
**Token Theft**: Short expiry, httpOnly cookies, HTTPS only
**CSRF**: SameSite cookies + CSRF tokens
**Session Fixation**: Regenerate session ID on login
**XSS**: Sanitize inputs, CSP headers
© patricio0312rev · MIT · patricio0312rev/skills