3

I am new to Nodejs and was trying to implement the session storage feature using Mongodb for storing the sessions of the user. Whenever the user logs in ,I am storing the session in the Mongodb database. But , I want to limit the number of active sessions of a single user like ( not more than 2 sessions). I am using PassportJS and "local-strategy" for authentication .The limit is greater than or equal to 2.

I was thinking of storing the user_id along with the session details in the MongoDB and then whenever a login is there, then I will check that user to the limit and send a response if it is not possible.

But , the problem is I am not able to think as How can I implement it! Please can anyone help me with this?

jack
  • 101
  • 1
  • 9
  • What is your os? – Janith Jul 01 '19 at 11:35
  • By active session do you mean the number of simultaneous connections? or can you please explain – Janith Jul 01 '19 at 11:40
  • I am using Windows 10 – jack Jul 01 '19 at 11:44
  • Yes, regarding the session you are right . I need to manage the simultaneous connections. Setting a limit and checking whenever a login is there , for each user. – jack Jul 01 '19 at 11:46
  • passport js may use cookies to identify users, so there might be multiple connections per user (based on cookies where same ip might have one or more cookies) or you may limit by the number of connections by ip. Which one are you looking for? – Janith Jul 01 '19 at 11:47
  • If it is possible that there are multiple cookies for a single IP, then I will like to count the no of active sessions per user based on the IP. I think , that would be the right approach of allowing a single user per IP.But , the problem is I dont know , how can I implement it.If you could help me ? – jack Jul 01 '19 at 12:01
  • Possible duplicate of [Express.js + Passport.js : How to restrict multiple login by the same user?](https://stackoverflow.com/questions/29144827/express-js-passport-js-how-to-restrict-multiple-login-by-the-same-user) – Aritra Chakraborty Jul 01 '19 at 12:26
  • 1
    @AritraChakraborty , First of all thanks for the link , it is quite close to what I need but the link that you mentioned has the solution of allowing only one active session at a time , but instead I want a limited number of sessions >=2. – jack Jul 01 '19 at 12:33

0 Answers0