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?