-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
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
[useResponseCache] Provide server context to define session Id #3282
Comments
We can change the |
The 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, |
Closed by #3520 |
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 the
request
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 the
req
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 complete
request
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.The text was updated successfully, but these errors were encountered: