# jwt-authentication-middleware

> Express middleware for JWT authentication.

Latest version **1.0.2** (published 2024-04-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install jwt-authentication-middleware
pnpm add jwt-authentication-middleware
yarn add jwt-authentication-middleware
bun add jwt-authentication-middleware
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2024-04-17 |
| First published | 2024-03-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | stelmach |
| Keywords | jwt, authentication, middleware, express |

## Links

- npm: https://www.npmjs.com/package/jwt-authentication-middleware
- Repository: https://github.com/stelmachreta/jwt-authentication-middleware
- Homepage: https://github.com/stelmachreta/jwt-authentication-middleware#readme
- Issues: https://github.com/stelmachreta/jwt-authentication-middleware/issues
- npm.io page: https://npm.io/package/jwt-authentication-middleware

## Dependencies (3)

- [express](https://npm.io/package/express.md) ^4.17.1
- [bcryptjs](https://npm.io/package/bcryptjs.md) ^2.4.3
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2024-04-17
- 1.0.1 — 2024-03-21
- 1.0.0 — 2024-03-18

## README

# JWT Authentication Middleware

JWT Authentication Middleware is a JavaScript library that provides middleware for JWT (JSON Web Token) authentication in Express.js applications. It helps secure routes by verifying JWT tokens and attaching decoded user information to incoming requests.

## Installation

To install the JWT Authentication Middleware library, use npm:

```bash
npm install jwt-authentication-middleware
```

## Usage

```javascript
const express = require('express');
const JWTAuthenticationMiddleware = require('jwt-authentication-middleware');

const app = express();

// Initialize the middleware with options
const jwtAuthMiddleware = new JWTAuthenticationMiddleware({
  secret: 'your_jwt_secret',
  excludedPaths: ['/public', '/login'] // Paths excluded from authentication
});

// Add middleware to the Express app
app.use(jwtAuthMiddleware.middleware());

// Protected route
app.get('/protected', (req, res) => {
  res.json({ message: 'Protected route accessed successfully!', user: req.user });
});

app.listen(3000, () => {
  console.log('Server started on port 3000');
});
```

## Options

- `secret`: (required) Secret key used to sign and verify JWT tokens.
- `excludedPaths`: (optional) Array of paths to exclude from JWT authentication. Requests to these paths will bypass authentication.

## API

### JWTAuthenticationMiddleware(options)

Creates a new instance of the JWTAuthenticationMiddleware.

#### Parameters

- `options` (Object):
    - `secret` (String): Secret key for JWT token validation.
    - `excludedPaths` (Array): Array of paths to exclude from authentication.

### middleware()

Returns the middleware function for use with Express.js.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---
_Source: https://npm.io/package/jwt-authentication-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
