xiaohongshu
xiaohongshu
jwt-auth-expert
Comprehensive JWT authentication expert for senior developers (10+ years experience). Intelligently detects project language/framework and implements production-ready JWT auth systems with refresh tokens, secure HTTP-only cookies, token rotation, blacklisting, RBAC, MFA, and complete security. Co...
Full skill instructions
Comprehensive senior-level JWT authentication assistant that intelligently detects your project stack and implements production-ready, secure authentication systems.
Complete Auth System
Security Implementation
Advanced Features
Framework Support
When triggered, automatically execute:
# Detect language and framework
view package.json # Node.js project
view requirements.txt # Python project
view pyproject.toml # Python with modern tools
view next.config.js # Next.js
view tsconfig.json # TypeScript
# Scan existing auth
view src/
view app/
view routes/
view middleware/
view models/
Based on detected files:
Check for:
Generate based on stack:
{
"sub": "user_id", // Subject (user identifier)
"email": "[email protected]",
"role": "admin", // For RBAC
"permissions": ["read", "write"],
"iat": 1234567890, // Issued at
"exp": 1234568790, // Expires (15 min from iat)
"jti": "unique_token_id" // JWT ID for blacklisting
}
{
"sub": "user_id",
"type": "refresh",
"tokenFamily": "family_id", // For rotation detection
"iat": 1234567890,
"exp": 1235172690 // 7 days
}
// ❌ NEVER DO THIS - Vulnerable to XSS
localStorage.setItem('token', token)
// ✅ CORRECT - HTTP-only cookie
res.cookie('accessToken', token, {
httpOnly: true, // Not accessible via JavaScript
secure: true, // HTTPS only
sameSite: 'strict', // CSRF protection
maxAge: 15 * 60 * 1000 // 15 minutes
})
res.cookie('refreshToken', refreshToken, {
httpOnly: true,
secure: true,
sameSite: 'strict',
maxAge: 7 * 24 * 60 * 60 * 1000, // 7 days
path: '/api/auth/refresh' // Only sent to refresh endpoint
})
import bcrypt from 'bcrypt'
// Hash on registration
const hashedPassword = await bcrypt.hash(password, 12) // 12 rounds minimum
// Verify on login
const isValid = await bcrypt.compare(password, user.hashedPassword)
1. Client request with expired access token
2. Server detects expiration → Check refresh token
3. Validate refresh token
4. Generate NEW access token + NEW refresh token (rotation)
5. Invalidate old refresh token (prevent reuse)
6. Set new tokens in HTTP-only cookies
7. Return success to client
// Store invalidated tokens in Redis/database
await redis.set(`blacklist:${tokenId}`, 'true', 'EX', tokenExpiry)
// Check on every request
const isBlacklisted = await redis.get(`blacklist:${tokenId}`)
if (isBlacklisted) {
throw new UnauthorizedError('Token has been revoked')
}
1. Registration
POST /api/auth/register
{
"email": "[email protected]",
"password": "SecurePass123!",
"name": "John Doe"
}
→ Hash password (bcrypt)
→ Create user in database
→ Generate email verification token
→ Send verification email
→ Return success (NO tokens yet)
2. Email Verification
GET /api/auth/verify-email?token=verification_token
→ Verify token validity
→ Mark email as verified
→ Allow user to login
3. Login
POST /api/auth/login
{
"email": "[email protected]",
"password": "SecurePass123!"
}
→ Validate credentials
→ Check email verified
→ Generate access token (15min)
→ Generate refresh token (7 days)
→ Store refresh token in database
→ Set HTTP-only cookies
→ Return user info (NO tokens in body)
4. Access Protected Route
GET /api/users/profile
Cookie: accessToken=xxx; refreshToken=yyy
→ Extract token from cookie
→ Verify token signature
→ Check expiration
→ Check blacklist
→ Attach user to request
→ Continue to route handler
5. Token Refresh (When Access Token Expires)
POST /api/auth/refresh
Cookie: refreshToken=xxx
→ Extract refresh token from cookie
→ Verify refresh token
→ Check if revoked/blacklisted
→ Generate NEW access token
→ Generate NEW refresh token (rotation)
→ Invalidate old refresh token
→ Set new cookies
→ Return success
6. Logout
POST /api/auth/logout
Cookie: accessToken=xxx; refreshToken=yyy
→ Extract tokens
→ Blacklist access token
→ Delete refresh token from database
→ Clear cookies
→ Return success
For framework-specific implementations, load:
Critical (Auto-Fix Immediately)
High Priority (Propose & Fix)
Medium Priority (Recommend)
// Middleware-based with cookie-parser
app.use(cookieParser())
app.use('/api/protected', authenticateToken)
// Token in HTTP-only cookie
res.cookie('accessToken', token, cookieOptions)
// Middleware for route protection
export function middleware(request: NextRequest) {
const token = request.cookies.get('accessToken')
// Verify and protect routes
}
// API routes with cookies
import { cookies } from 'next/headers'
cookies().set('accessToken', token, cookieOptions)
# Dependency injection
async def get_current_user(token: str = Cookie(...)):
# Verify token from cookie
return user
@app.get("/protected")
async def protected_route(user = Depends(get_current_user)):
return {"user": user}
Complete Auth System: "Create a complete JWT auth system for Express with refresh tokens in cookies"
Add to Existing: "Add JWT authentication to my Next.js app"
Security Audit: "Audit my JWT implementation for security vulnerabilities"
Protected Routes: "Implement JWT middleware for protected routes"
RBAC: "Add role-based access control to my auth system"
Frontend: "Implement JWT auth in React with protected routes"
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience