We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FastifyInterface
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @fastify/jwt@7.2.4 for the project I'm working on.
@fastify/jwt@7.2.4
When using the namespace option, the fastify.jwt object no longer contains the JWT interface, but the namespace objects.
fastify.jwt
JWT
In my case, I created two namespaces auth and refresh and the fastify.jwt now contains auth: JWT, refresh: JWT.
auth
refresh
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 --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<string>
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered:
This is definitely something we would need to fix for Fastify v5 (fastify/fastify#5061)
Sorry, something went wrong.
Here is my workaround when using the 'player' namespace.
I found that FastifyJwtNamespace doesn't augment FastifyRequest and FastifyReply interfaces, but incorrectly FastifyInstance.
FastifyJwtNamespace
FastifyRequest
FastifyReply
FastifyInstance
import type { FastifyPluginCallback } from 'fastify' import type { FastifyJWTOptions, FastifyJwtNamespace } from '@fastify/jwt' import jwt from '@fastify/jwt' declare module 'fastify' { interface FastifyInstance extends FastifyJwtNamespace<{ namespace: 'player' }> {} interface FastifyRequest { // Custom namespace playerJwtVerify: FastifyRequest['jwtVerify'], playerJwtDecode: FastifyRequest['jwtDecode'], } interface FastifyReply { // Custon namespace playerJwtSign: FastifyReply['jwtSign'], } } declare module '@fastify/jwt' { // Custom Namespace (undocumented) interface JWT { player: jwt.JWT } } const jwtPlayerPlugin: FastifyPluginCallback = async (fastify) => { fastify.register(jwt, { namespace: 'player', }) })
I'm having the same issue, it looks like the types are wrong
No branches or pull requests
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used 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 theJWT
interface, but the namespace objects.In my case, I created two namespaces
auth
andrefresh
and thefastify.jwt
now containsauth: 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:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: