JWT Authentication Implementation
Implement secure JWT-based authentication with refresh tokens
Implement JWT authentication for: **Stack:** [STACK — e.g., "Next.js API routes + PostgreSQL"] **User model:** [FIELDS — e.g., "email, password, role, organization_id"] Generate: 1. **Token pair** — short-lived access token (15min) + long-lived refresh token (7d) 2. **Login flow** — validate credentials, issue token pair, set httpOnly cookies 3. **Token refresh** — silent refresh before access token expires 4. **Logout** — invalidate refresh token, clear cookies 5. **Middleware** — verify token, attach user to request context 6. **Password hashing** — bcrypt with proper salt rounds 7. **Security headers** — CSRF protection, SameSite cookies, Secure flag 8. **Token rotation** — new refresh token on each refresh (detect token reuse) Security requirements: - Never store tokens in localStorage - Refresh tokens stored in DB for revocation - Rate limit login attempts - Constant-time password comparison Include all route handlers, middleware, and database schema.
How to Use This Prompt
- 1Copy the prompt template above
- 2Paste into Claude, ChatGPT, or Cursor
- 3Replace [bracketed placeholders] with your specific project details
- 4Iterate on the AI output to refine and customize the results
More Security Prompts
Related security templates from the vault
SQL Injection Prevention Guide
Use this prompt to sql injection prevention guide with AI assistance
Supply Chain Attack Prevention Checklist
PROAudit and harden your software supply chain against dependency attacks, compromised packages, and build pipeline tampering
OWASP Top 10 Audit Checklist
Use this prompt to owasp top 10 audit checklist with AI assistance
Content Security Policy Builder
PROGenerate a strict Content Security Policy for your web application
You Might Also Like
Prompts from other categories that share similar tags
Authentication System with JWT
Implement a complete authentication system with signup, login, and session management
Session Management with Redis
Use this prompt to session management with redis with AI assistance
Audit Log System Implementation
Use this prompt to audit log system implementation with AI assistance
API Key Management System
Use this prompt to api key management system with AI assistance
Keep Exploring the Vault