Prompt to Create a Complete JWT Authentication System
A complete prompt to generate a secure JWT authentication system with token management, refresh tokens, middleware and security best practices.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
You are a senior backend developer specializing in application security. Design a complete JWT authentication system for a [language/framework] application with the following specifications:
-
System architecture:
- Registration endpoint with data validation (email, strong password)
- Login endpoint returning an access token and a refresh token
- Token refresh endpoint
- Logout endpoint with token invalidation
- Authentication middleware to protect routes
-
Required security:
- Password hashing with bcrypt (configurable salt rounds)
- Short-lived access token ([access token duration]) and long-lived refresh token ([refresh token duration])
- Secure storage of refresh tokens in the database with the ability to revoke them
- Protection against brute-force attacks (rate limiting)
- Refresh token rotation on every use
- Strict validation of the JWT payload
-
Expected structure:
- User model with the necessary fields
- Authentication service separate from controller logic
- Centralized error handling (expired token, invalid token, user not found)
- Environment variables for secrets and configuration
- Types/interfaces if the language allows it
-
Database: [database type]
-
Bonus:
- Unit tests for critical functions (token generation, verification, hashing)
- Endpoint documentation in OpenAPI/Swagger format
- Example of a protected route with user data extracted from the token
Provide the complete code, commented in French, along with the commands to install the necessary dependencies. Explain each security choice.
Personalize this prompt with Léa · AI assistant
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
This prompt guides AI to produce a professional and secure JWT authentication system. By specifying your language or framework (Node.js/Express, Python/FastAPI, Java/Spring Boot, etc.), token duration and database type, you get code tailored to your exact tech stack. The prompt structure enforces a layered architecture (controllers, services, middleware) that reflects industry best practices. The security requirements — refresh token rotation, rate limiting, bcrypt hashing — ensure the generated code goes beyond a basic example and constitutes a solid foundation for production. Usage tips: start by replacing the bracketed variables, then iterate. Next, ask the AI to add features like two-factor authentication, role management (RBAC), or integration with an OAuth provider (Google, GitHub). You can also request an adaptation for a microservices architecture with a centralized authentication service.
Use Cases
Expected Output
A complete authentication system with commented source code: user model, authentication service, controllers for signup/login/refresh/logout, route protection middleware, configuration file, installation commands and unit tests.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
Pour un résultat plus précis, remplacez [LANGAGE/FRAMEWORK] et [TYPE_BASE_DE_DONNEES] par des valeurs concrètes (ex. Node.js/Express + PostgreSQL) et ajoutez des exigences de sécurité : stockage des refresh tokens avec un identifiant unique (jti) et date d’expiration en base, révocation explicite, et envoi du refresh token dans un cookie HttpOnly (jamais en localStorage) pour limiter les risques XSS.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Design an event-driven system
Architect event-driven systems
Write a deployment script
Automate deployment scripts
Prompt ChatGPT to Generate SQL Queries
Generating SQL queries is an essential skill for any developer, data analyst, or database administrator. However, writing complex queries involving multiple joins, nested subqueries, or aggregate functions can be time-consuming and error-prone. ChatGPT transforms this practice radically by allowing you to describe your needs in natural language to obtain optimized and functional SQL queries in seconds. Whether you work with MySQL, PostgreSQL, SQL Server, or SQLite, the AI adapts to the specific syntax of your database management system. By providing your table schema and a clear description of what you want, you can generate perfectly structured SELECT, INSERT, UPDATE, or DELETE queries. ChatGPT also excels at line-by-line explanations of generated queries, making it a valuable learning tool for beginners and professionals alike who wish to explore advanced SQL features like CTEs, window functions, or recursive queries.
Master Git Reset, Rebase, and Cherry-Pick
Master advanced Git commands (reset, rebase, cherry-pick, stash) with clear diagrams and practical scenarios.