#Having a session id that is available in a nested call stack

7 messages · Page 1 of 1 (latest)

urban haven
#

I have a scenario where I want each user to have its own session ID, this session ID will be stored with certain parameters that affect the user's request.
what would be the best way to achieve this ?
I want o hold a session id that is available throughout the flow
I saw that there is a @Session decorator but I want it to be available in every function in the flow, so what should I do ?

One option that is that I can propagate it on every function call, but I want something elegant

errant epoch
#

Sounds like you either want nestjs-cls to use async local storage, or make your services REQUEST scope and pull the session from the request

urban haven
#

what if there are part of the code that are not in a class and not part of the Nest.js code ?

zealous slate
# urban haven what if there are part of the code that are not in a class and not part of the N...

you're going to be in a tough spot then
all the data regarding sessions are stored in req.session @Session() is just a shorthand
if you do not have access to the rquest object it is not going to be easy

what if there are part of the code that are not in a class and not part of the Nest.js code ?
unless you pass the the session or parts of it to a function param you're going to hit a dead end i'm afraid
can you give a example of your issue perhaps we can find a work around

cedar shadow
zealous slate
cedar shadow