Express Middleware with Authentication
Securing API routes with JWT authentication
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Write an Express middleware in TypeScript to authenticate requests using JWT. The middleware must: check the Authorization Bearer header, decode and validate the token with the secret key, attach the decoded user to req.user, return explicit 401/403 errors, and handle token expiration. Add structured logging with winston.
Personalize this prompt with Léa
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Use Cases
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 une meilleure maintenabilité, isolez la validation du token dans une fonction utilitaire dédiée. Utilisez `jsonwebtoken.verify()` avec `process.env.JWT_SECRET` et augmentez le type Express `Request` pour ajouter `user`. Gérez l’expiration via l’option `expiresIn` côté émission.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Course Deployment Guide
Course Deployment
Perplexity Prompt to Create a Chatbot
Perplexity stands out from other AI assistants due to its ability to search and synthesize information from the web in real time. To create a chatbot, this feature is invaluable: Perplexity can identify the latest frameworks, compare current technical solutions, and provide recommendations based on the state of the art. Whether you want to develop a customer support chatbot, an internal conversational assistant, or a specialized domain bot, Perplexity guides you through architectural choices, available APIs, and implementation best practices. By combining documented research with code generation, it enables you to quickly move from concept to functional prototype, while relying on verifiable sources for every technical recommendation.
Create a React component
Scaffold new UI components quickly
Design a multi-cluster strategy
Design multi-cluster architectures