Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the session Id when using express / connect and a session store?

If a user is already logged in and tries to login again in a new instance I'd like it to log out the other user instance. I don't want the same user to be logged in twice on my application.

Currently the session is stored in a Redis store, i'm using express / connect to handle the session storage. One of the functions available which could be used to destroy the session is as follows:

.destroy(sid, callback) 

However I need to find that session id before I call .destroy(). In Redis the username is stored as a part of the session.

Question: Is it possible to query Redis to obtain the session id based on the username?

like image 701
Jack Avatar asked Feb 15 '12 10:02

Jack


People also ask

Where is session data stored in Express session?

With express-session in particular, it has a built-in "not-meant-for-production" memory store (so session data is kept in memory and would not survive a server restart).

What is session in Express js?

Advertisements. HTTP is stateless; in order to associate a request to any other request, you need a way to store user data between HTTP requests. Cookies and URL parameters are both suitable ways to transport data between the client and the server. But they are both readable and on the client side.

How do Sessions work in Express?

Overview. Express. js uses a cookie to store a session id (with an encryption signature) in the user's browser and then, on subsequent requests, uses the value of that cookie to retrieve session information stored on the server.

What is Express session secret?

The session secret is a key used for signing and/or encrypting cookies set by the application to maintain session state.


1 Answers

req.sessionID will provide you the session's ID, where req is a request object.

like image 155
Joe H Avatar answered Sep 28 '22 00:09

Joe H