Skip to content
Back to skills

Auth Middleware

ASecurity

Generates authentication and authorization middleware for Express/Fastify/Hono

  • 10 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 1, 2026
ai-agentsbashexpressapi

Works with

  • api

Security analysis

A100/100

Scanned June 1, 2026

npx -y skills add berkcangumusisik/claude-code-practices --skill auth-middleware --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Auth Middleware?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Auth Middleware
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/berkcangumusisik-auth-middleware/badge)](https://www.skillsdirectory.com/skills/berkcangumusisik-auth-middleware)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: auth-middleware
description: Generates authentication and authorization middleware for Express/Fastify/Hono
argument-hint: <strategy: jwt|session|api-key|oauth>
user-invocable: true
allowed-tools: Read Glob Edit
effort: medium
---

## Generate Auth Middleware

Strategy: **$1** (jwt | session | api-key | oauth)

1. Detect framework and existing auth patterns:
```bash
cat package.json | grep -E '"express"|"fastify"|"hono"|"jsonwebtoken"|"jose"|"passport"'
grep -rn "middleware\|authenticate\|authorize" src/ --include="*.ts" -l | head -5
```

2. Read existing auth code if present.

3. Generate the middleware for the requested strategy:

**JWT example:**
```ts
export async function authenticate(req: Request, res: Response, next: NextFunction) {
  const token = req.headers.authorization?.split(' ')[1]
  if (!token) return res.status(401).json({ error: 'Unauthorized' })
  
  try {
    const payload = await verifyJWT(token)
    req.user = payload
    next()
  } catch {
    return res.status(401).json({ error: 'Invalid token' })
  }
}

export function authorize(...roles: Role[]) {
  return (req: Request, res: Response, next: NextFunction) => {
    if (!roles.includes(req.user?.role)) return res.status(403).json({ error: 'Forbidden' })
    next()
  }
}
```

4. Include:
   - Token refresh logic (if JWT)
   - Rate limiting for auth endpoints
   - Brute force protection (lockout after N failures)
   - Proper error messages (don't leak info)

5. Generate tests for all auth scenarios.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…