fastify / fastify/fastify-jwt

`FastifyInterface` TypeScript augmentation when using namespaces

Open
#321 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
586
Forks
120
PR merge metrics
No merged PRs in 30d

Description

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used [patch-package](https://github.com/ds300/patch-package) to patch `@fastify/jwt@7.2.4` for the project I'm working on.

When using the namespace option, the `fastify.jwt` object no longer contains the `JWT` interface, but the namespace objects.

In my case, I created two namespaces `auth` and `refresh` and the `fastify.jwt` now contains `auth: JWT, refresh: JWT`.

Unfortunately, I wasn't able to override the augmentation, so I commented it out for the moment.

Maybe this should be left for the implementation to be typed.

Here is the diff that solved my problem:

```diff
diff --git a/node_modules/@fastify/jwt/types/jwt.d.ts b/node_modules/@fastify/jwt/types/jwt.d.ts
index d9bc2b4..7d1605b 100644
--- a/node_modules/@fastify/jwt/types/jwt.d.ts
+++ b/node_modules/@fastify/jwt/types/jwt.d.ts
@@ -13,9 +13,11 @@ import {
} from 'fastify'

declare module 'fastify' {
- interface FastifyInstance {
- jwt: fastifyJwt.JWT
- }
+ // PATCH: If namespaces are used, the `jwt` object will contain the namespaces as a property.
+ // This augmentation prevents later augmentations from overwriting the namespace property.
+ // interface FastifyInstance {
+ // jwt: fastifyJwt.JWT
+ // }

interface FastifyReply {
jwtSign(payload: fastifyJwt.SignPayloadType, options?: fastifyJwt.FastifyJwtSignOptions): Promise
```

This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.