Skip to content
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

Updating variables stored in the req session can result in false values #462

Open
piphansdk opened this issue Dec 19, 2022 · 0 comments
Open

Comments

@piphansdk
Copy link

Hi,

We are trying to use the session of a user to store variables which needs to be used in different pages. The issue with the solution, is that the session seems to have an issue always updating the session in mongoDB.

Process:

  1. The user will access a URL, the function of the URL is to have NodeJS to update a variable stored in res.user.someValue
  2. NodeJS will call res.redirect
  3. The user will access the redirected URL. NodeJS is processing the request and getting res.user.someValue. This value is not identical to the one just set in step 1.

The issue was thoroughly tested using an automated test. The test ran 100 times on a Mac m1, which resulted in 30 cases where req.user.someValue was the old variable. In the same test on an older windows machine the test failed 5 times out of 100.

We are using the following for setting up our session store.

app.use( expressSession({ secret: process.env.COOKIE_SECRET_KEY, cookie: { sameSite: "lax", secure: process.env.SECURECOOKIE == "TRUE", domain: process.env.COOKIEDOMAIN }, proxy: true, resave: true, saveUninitialized: true, store: MongoStore.create({ mongoUrl: config.databaseUri, mongoOptions: {loggerLevel: "debug"}, autoRemove: 'interval', autoRemoveInterval: 10 // Value in minutes (default is 10) }) }) );

We wanted to further debug everytime the session was stored in mongo and collected from mongo, but we simply cannot start the debugging in any format for the module.

We are using the following versions:
NodeJS v. 18.12.1 MongoDB v. 5.0.14 "connect-mongo": "^4.6.0", "express": "4.x", "express-session": "^1.17.3",

we'd appreciate any help we can get. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant