# @byu-oit-sdk/fastify-jwt

> Fastify plugin for verifying JWTs in fastify server requests

Latest version **0.4.0** (published 2026-04-29) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @byu-oit-sdk/fastify-jwt
pnpm add @byu-oit-sdk/fastify-jwt
yarn add @byu-oit-sdk/fastify-jwt
bun add @byu-oit-sdk/fastify-jwt
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2026-04-29 |
| First published | 2023-08-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 4 |
| Unpacked size | 32.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Spencer Tuft |
| Maintainers | stuft2, byu-oit-bot |

## Links

- npm: https://www.npmjs.com/package/@byu-oit-sdk/fastify-jwt
- Repository: https://github.com/byu-oit-sdk/javascript
- Homepage: https://github.com/byu-oit-sdk/javascript#readme
- Issues: https://github.com/byu-oit-sdk/javascript/issues
- npm.io page: https://npm.io/package/@byu-oit-sdk/fastify-jwt

## Dependencies (4)

- [tslib](https://npm.io/package/tslib.md) ^2.5.0
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^5.1.0
- [@byu-oit-sdk/jwt](https://npm.io/package/@byu-oit-sdk/jwt.md) ^0.4.0
- [@sinclair/typebox](https://npm.io/package/@sinclair/typebox.md) ^0.34.41

## Recent versions

- 0.4.0 (latest) — 2026-04-29
- 0.3.1 — 2026-04-07
- 0.3.0 — 2026-04-06
- 0.2.0 — 2025-07-22
- 0.1.22 — 2025-05-01
- 0.1.21 — 2025-04-01
- 0.1.20 — 2025-03-18
- 0.1.19 — 2025-03-12
- 0.1.18 — 2025-02-20
- 0.1.17 — 2025-02-19
- 0.1.16 — 2025-01-22
- 0.1.15 — 2025-01-21
- 0.1.14 — 2024-11-14
- 0.1.13 — 2024-10-29
- 0.1.12 — 2024-10-11
- … 28 more at https://npm.io/package/@byu-oit-sdk/fastify-jwt/versions

## README

# @byu-oit-sdk/fastify-jwt

**Requirements**:

- Node.js 20+
- npm v9+
- Fastify v5

## Breaking Changes

- `@byu-oit-sdk/fastify-jwt` now requires Node.js 20 or newer.
- `@byu-oit-sdk/fastify-jwt` now targets Fastify 5.

## Installing


```shell
npm install @byu-oit-sdk/fastify-jwt
```

## Introduction

This fastify middleware allows for verification and decoding of JWTs.

## Options

> Along with the options for the CreateJwt() function (see docs for jwt package), the following options can be passed in when registering the middleware with fastify.

| Option            | Type                                        | Default | Description                                                                                                        |
|-------------------|---------------------------------------------|---------|--------------------------------------------------------------------------------------------------------------------|
| prefix            | string                                      | -       | Used to specify what route the middleware is registered with.                                                      |
| transformer       | JwtPayloadTransformer<Payload, Transformer> | -       | The function that you will use for manipulating the JWT you are authenticating.                                    |
| getJwt            | function                                    | -       | A function for getting the JWT from the request. By default, the JWT is pulled from the auth header.               |
| validate          | boolean                                     | -       | Boolean used to signify if we want to validate the jwt if true, or just decode it if false.                        |

## Usage

<details>
<summary>TypeScript Coding Example</summary>


```typescript
import Fastify from 'fastify'
import { FastifyJwtProvider } from '@byu-oit-sdk/fastify-jwt'
import { Type } from '@sinclair/typebox'

// set up fastify server
const app = Fastify({
  logger: true
})

// declare transformer
const transformer = (payload: { 'http://byu.edu/claims/client_preferred_first_name': string }): { preferred_first_name: string } => ({ preferred_first_name: payload['http://byu.edu/claims/client_preferred_first_name'] })

// register the middleware with Fastify
await app.register(FastifyJwtProvider, { schema: Type.Object({ }, { additionalProperties: true }), key: '', validate: false, transformer })

// declare endpoint
app.get('/', async (request, reply) => {
  return request.caller
})

// send a request
const response = await app.inject({
  method: 'GET',
  url: '/',
  headers: {
    Authorization: /* A valid token */
  }
})

console.log(response)


```

</details>

---
_Source: https://npm.io/package/@byu-oit-sdk/fastify-jwt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
