P
💻DeveloppementIntermediateAll AIs

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.

Tu es un développeur backend senior spécialisé en sécurité applicative. Conçois un système d'authentification JWT complet pour une application [LANGAGE/FRAMEWORK] avec les spécifications suivantes :

  1. Architecture du système :

    • Endpoint d'inscription avec validation des données (email, mot de passe fort)
    • Endpoint de connexion retournant un access token et un refresh token
    • Endpoint de rafraîchissement du token
    • Endpoint de déconnexion avec invalidation du token
    • Middleware d'authentification pour protéger les routes
  2. Sécurité obligatoire :

    • Hashage des mots de passe avec bcrypt (salt rounds configurable)
    • Access token courte durée ([DUREE_ACCESS_TOKEN]) et refresh token longue durée ([DUREE_REFRESH_TOKEN])
    • Stockage sécurisé des refresh tokens en base de données avec possibilité de révocation
    • Protection contre les attaques par force brute (rate limiting)
    • Rotation des refresh tokens à chaque utilisation
    • Validation stricte du payload JWT
  3. Structure attendue :

    • Modèle utilisateur avec les champs nécessaires
    • Service d'authentification séparé de la logique des contrôleurs
    • Gestion centralisée des erreurs (token expiré, invalide, utilisateur non trouvé)
    • Variables d'environnement pour les secrets et la configuration
    • Types/interfaces si le langage le permet
  4. Base de données : [TYPE_BASE_DE_DONNEES]

  5. Bonus :

    • Tests unitaires pour les fonctions critiques (génération token, vérification, hashage)
    • Documentation des endpoints au format OpenAPI/Swagger
    • Exemple de route protégée avec extraction des données utilisateur depuis le token

Fournis le code complet, commenté en français, avec les commandes d'installation des dépendances nécessaires. Explique chaque choix de sécurité.

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

Why this prompt works

<p>This prompt guides AI to produce a professional and secure JWT authentication system. By specifying your <strong>language or framework</strong> (Node.js/Express, Python/FastAPI, Java/Spring Boot, etc.), <strong>token duration</strong> and <strong>database type</strong>, you get code tailored to your exact tech stack.</p><p>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.</p><p><strong>Usage tips</strong>: start by replacing the bracketed variables, then iterate. Next, ask the AI to add features like <strong>two-factor authentication</strong>, <strong>role management</strong> (RBAC), or integration with an <strong>OAuth provider</strong> (Google, GitHub). You can also request an adaptation for a microservices architecture with a centralized authentication service.</p>

Use Cases

Create REST API authentication from scratchSecure an existing application by replacing sessions with JWTsSet up a fullstack project with complete user managementLearn JWT security best practices by example

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 Optimizer

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

Helm Chart for Application

Create a Helm chart

075
💻DeveloppementAdvancedAll AIs

Implement drift detection

Detect infrastructure drift

059
💻DeveloppementAdvancedAll AIs

Analyze and Optimize Algorithmic Complexity

Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.

40309
💻DeveloppementAdvancedAll AIs

Design a security incident response plan

Prepare for security incidents

044