Closed deeeed closed 2 years ago
Hi, I'm not familiar with SessionModule
, but after a brief look at the code, I can see that they set up the middleware in a similar manner to ClsModule
, so the middleware registration order probably follows the order in which Nest resolves the modules (they use topological sorting, but I don't really know how they treat global modules).
You might fix it by setting mount
to false
and mounting the ClsMiddleware
in the root module (AppModule
)
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
apply(ClsMiddleware).forRoutes('*');
}
}
If that doesn't work, I was about to suggest the extra interceptor method, that you already use.
Another option would be to not use SessionModule
and attach a plain old express-session
middleware as outlined in the docs here https://docs.nestjs.com/techniques/session#session
@deeeed Please tell me if your issue was resolved by one of the proposed solutions, so I can close it.
Hi,
I am trying to setup the context to holds my sessionId as well but the ClsModule setup is always running before my SessionModule setup (hence session is not available in ClsModule context).
If I look at the log I get:
Any recommendation to fix this issue? Currently I create a separate interceptor that complements the setup and adds the session attribute to my context.