P
đź’»DeveloppementIntermediateAll AIs

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

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

Use Cases

Securing API routes with JWT authentication

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • 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

đź’»DeveloppementIntermediateAll AIs

Namespace and Quota Management

Manage a multi-tenant cluster

0110
đź’»DeveloppementAdvancedAll AIs

Build a virtualized list

Handle massive data lists

0145
đź’»DeveloppementIntermediateAll AIs

Social Content A/B Test

Testing and optimizing content

098
đź’»DeveloppementIntermediateChatGPT

Optimize React Application Performance

Optimize your React application to achieve excellent Core Web Vitals metrics through advanced memoization and code splitting techniques.

36394