Open santino opened 1 month ago
We can change the sessionId
factory to pass the server context as the second parameter but I am curious what do you need from the server context specifically?
The request
object from my server context has a number of decorators that can be useful to define the session.
In my specific case, I add an authenticatedUser
object containing information retrieved and validated from an authentication cookie.
Within the opaque Yoga request object I just have the parameters passed with the request. So I can see the plain cookie string which also contains my authentication cookie. But then I'd need to split it; extract the authentication cookie, parse the JWT, validate it, and finally extract the userId.
I am doing all this stuff within my Fastify decorator and I don't certainly want to process the cookie string manually and process the authentication cookie for the second time; considering all the data I need is available in the server context.
Hello folks, what's your plan on #3285 can I help with anything to get the PR merged?
Hello folks, I am struggling to properly implement session-based caching for
useResponseCache
Yoga plugin.I don't have any usable header with a fully formed user id passed within the client request. Instead, I have cookies which are handled by my Fastify server instance through an
onRequest
hook. Ultimately if a valid user session can be derived from the cookies, a user/session id will be decorated within therequest
object of my server.Here comes the problem with
useResponseCache
. Thesession
function only gets passed the yogarequest
object which is aPonyfillRequest
instance. Since this does not receive thereq
object from my server, I have no chance to read my decorated object containing information about the user session. This is effectively a blocker that makes this plugin unusable for me.To work around this issue I had to create a custom
useResponseCache
plugin in order to provide theserverContext
to thesession
function. In this case, I am duplicating the Yoga plugin and I will need to keep it up to date. Maybe you can consider passing a more completerequest
object to thesession
function or more arguments to include the server context in its entirety.I am pasting the code I used for my custom implementation of the plugin. I literally added 3 lines of code to just pass the
serverContext
betweenonRequest
andonParams
so it can be provided to thesessions
function.