Obtain a list of active sessions

1,029 views
Skip to first unread message

Jacob Beard

unread,
Mar 8, 2014, 1:14:12 PM3/8/14
to expre...@googlegroups.com
Hi,

I'm building a web app with express, and I'm trying to figure out how I can obtain a list of active sessions. Do I need to maintain this list myself (e.g. updating an in-memory data structure on user login and logout), or does express keep track of it? Are there any third-party modules that would handle this for me?

Jake

Paul Vencill

unread,
Mar 9, 2014, 1:20:19 AM3/9/14
to expre...@googlegroups.com
Officially it depends on which Store you use for your session.  MemoryStore includes a 'all' method that fetches them for you:

but MongoStore does not.  In that case, though, you could just query the DB for the collection that holds the sessions.  I don't think it's a common use case to actually enumerate the active sessions.  If you just want a count, then most of them seem to follow the "recommendation" and implement a length method.


--
You received this message because you are subscribed to the Google Groups "Express" group.
To unsubscribe from this group and stop receiving emails from it, send an email to express-js+...@googlegroups.com.
To post to this group, send email to expre...@googlegroups.com.
Visit this group at http://groups.google.com/group/express-js.
For more options, visit https://groups.google.com/d/optout.

Jacob Beard

unread,
Mar 9, 2014, 10:59:09 AM3/9/14
to expre...@googlegroups.com
Thanks for the reply. I'm using RedisStore. I guess I could query Redis.

Jacob Beard

unread,
Mar 9, 2014, 11:25:02 AM3/9/14
to expre...@googlegroups.com
Ultimately, what I am trying to do is prevent a user account from being used to log in multiple times. The way I was considering implementing this was as follows: on user login attempt, check all active sessions to see if there exists a session for that user account, and if there does, then reject that login attempt. Does this seem sensible?

Jake


On Sunday, March 9, 2014 1:20:19 AM UTC-5, Paul wrote:
Reply all
Reply to author
Forward
0 new messages