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

Anyone know how to properly use Session.touch()? #823

Open
v1v2v3vv55 opened this issue Apr 23, 2021 · 1 comment
Open

Anyone know how to properly use Session.touch()? #823

v1v2v3vv55 opened this issue Apr 23, 2021 · 1 comment

Comments

@v1v2v3vv55
Copy link

Hi folks,
as doc recommended, Session.touch() will reset the timer and session itself usually does it for you when setting rolling to true. But this time I'm actually trying to manually reset the timer by calling Session.touch(), I tried req.session.touch(), req.session.Session.touch(), and Session.touch(), they all are not working (the purpose of doing it is to fire a command to the backend and triggered touch command). What should I do in this case?

@jcrunge
Copy link

jcrunge commented Jun 5, 2023

Maybe you only need to use resave: true instead touch():

"Depending on your store this may be necessary, but it can also create race conditions where a client makes two parallel requests to your server and changes made to the session in one request may get overwritten when the other request ends, even if it made no changes (this behavior also depends on what store you're using).
The default value is true, but using the default has been deprecated, as the default will change in the future. Please research into this setting and choose what is appropriate to your use-case. Typically, you'll want false.
How do I know if this is necessary for my store? The best way to know is to check with your store if it implements the touch method. If it does, then you can safely set resave: false. If it does not implement the touch method and your store sets an expiration date on stored sessions, then you likely need resave: true."

my config:

app.use(session({
    ...
    store: sessionStore,
    saveUninitialized: false,
    resave: true,
}))

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

2 participants