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

Session time limit? Garbage collection? #41

Open
codepilotsf opened this issue Mar 8, 2023 · 2 comments
Open

Session time limit? Garbage collection? #41

codepilotsf opened this issue Mar 8, 2023 · 2 comments

Comments

@codepilotsf
Copy link

I can't find any feature to limit the length of a session or to clean up old sessions from the database (mongodb in my case). Is there some recommended way to handle this?

@jcs224
Copy link
Owner

jcs224 commented Mar 8, 2023

For session length limit, there's an option called expireAfterSeconds when you instantiate the session. It's not documented yet. If the session isn't valid when access is attempted after that expiry, it will be deleted.

app.use(Session.initMiddleware(store, { expireAfterSeconds: 900 })) // session will expire after 15 minutes of inactivity

If you want to get rid of stale sessions, there's a property stored with the other session data called _accessed that is updated whenever the session is read from or written to. You could come up with a cron job script to look for any sessions that have _accessed values that are older than a certain threshold. Maybe someday we will integrate this more tightly into the library.

@codepilotsf
Copy link
Author

Fantastic! Thank you!

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