Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Nodejs Websockets User Active State with MongoDB

I have a NodeJS backend with Express and WS, and is a simple messenger-like chat app. You login, then you chat. But I want to add a feature on top of it. If a user is already logged and ACTIVE (socket connection exists, not broken) I want it's activeStatus : active in database. So that if he tries to login from a different browser, if his activeStatus is active, he won't be able to connect.

How is this achievable? I cannot understand how am I supposed to link a websocket connection to a specific ID in database, and when connection is on, update db, and when connection drops, update it to that ID again.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just set a unique parameter for WebSocket instance in wss.on('connection',...) and use it later to identify the user. Also, if you aren't able to link websocket connection to a specified user, how does your authentication work? It seems like anyone can connect to your server, if it can't differentiate between users.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!