0

I am using satellizer in my second MEAN webapp and I need to avoid a user from loggin in twice at the same time (using two different computers).

My approach would be:

  1. Create a collection that stores the users that are logged in. Every time a user logs in, check if the user is not in the table. If there is not, add it. If there is, send error to frontend.

  2. When a the user logs out delete the user's document in the collection of logged in users.

I don't know if there is a more professional solution or an already built-in solution for satellizer, node.js or mongoose...

Egidi
  • 1,736
  • 8
  • 43
  • 69

1 Answers1

0

The communication between client-server-db will be an overhead if you want to store the logged in user in mongoDB collection. Instead use socket.io for maintaining an array of logged in usernames just at node server end. Push or pop the entries from the array based on whether an user logs in or log out.

Deepak Bansal
  • 115
  • 1
  • 5
  • Why would I need socket.io to do it? I can just have an array in the server and push or pop users every time they login/logout..? – Egidi Sep 22 '16 at 17:20
  • I think i need a little more help..I am quite newbie with node.js – Egidi Sep 22 '16 at 17:26