oak_sessions icon indicating copy to clipboard operation
oak_sessions copied to clipboard

Session time limit? Garbage collection?

Open codepilotsf opened this issue 2 years ago • 2 comments
trafficstars

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?

codepilotsf avatar Mar 08 '23 21:03 codepilotsf

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.

jcs224 avatar Mar 08 '23 23:03 jcs224

Fantastic! Thank you!

codepilotsf avatar Mar 08 '23 23:03 codepilotsf