-
Notifications
You must be signed in to change notification settings - Fork 34
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
[express-session] Can't keep session values with default options. #25
Comments
Workaround for now: setting sessionStore explicitly. Like export class ApiModule {
private sessionStore = new MemoryStore();
configure(consumer: MiddlewareConsumer) {
ExpressSessionMiddleware.configure({
store: this.sessionStore, |
can you open a PR? I didn't know it worked like this. I'd be happy to merge |
I had the same problem, I have the same problem. Each session cannot be saved my code
|
I'd be glad to accept a PR for this issue |
export class ExpressSessionMiddleware implements NestMiddleware {
// DELETE THESE LINES IF MIDDLEWARE DOES NOT TAKE OPTIONS
public static configure(opts: expressSession.SessionOptions) {
this.options = opts;
}
private static options: expressSession.SessionOptions;
private handler: Express.RequestHandler;
private getHandler() {
if (this.handler) return this.handler;
if (ExpressSessionMiddleware.options) this.handler = expressSession(ExpressSessionMiddleware.options);
else this.handler = expressSession();
return this.handler;
}
public use(req: any, res: any, next: any) {
this.getHandler()(req, res, next);
}
} Seems modify the function to singleton will work |
Fixed in 10.0.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In
@nest-middlewares/express-session
, always new session object is created per routing whenoptions
was applied.nest-middlewares/packages/express-session/index.ts
Lines 15 to 16 in 077baf8
And
express-session
creates new instance ofMemorySession
ifoption.store
wasn't specified.https://github.com/expressjs/session/blob/10607bdb780204b91a8cf90e4ce27726619b8285/index.js#L99-L100
So the app can't keep values in the session.
I suspect the value of
expressSession
should be cached in the classExpressSessionMiddleware
.The text was updated successfully, but these errors were encountered: