yubinTW / fastify-keycloak-adapter

a Fastify plugin for Keycloak
MIT License
19 stars 5 forks source link

Fix request.session type #33

Closed yubinTW closed 1 year ago

yubinTW commented 1 year ago

Problem

when using request.session.user to get an user, typescript will find the type error

Property 'user' does not exist on type 'FastifySessionObject'.ts(2339)

because session field in FastifyRequest is FastifySessionObject type (from @fastify/session)

ref: https://github.com/fastify/session/blob/74615c3ba1ad71689c48896ac82ae3629bec5ea0/types/types.d.ts#L14

Solution

Extends the FastifySessionObject interface in @fastify/session, rather than Session interface in fastify