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

202
Views
How to display users on current page?

For example I have a page with url "/foo", and I need to display my authenticated users nicknames on this page. Is there any default node.js/passport function for this, or I need to add every user of this page to database and display it with websockets?

User schema:

var userSchema = new Schema({
    email: {type: String, required: true, unique: true },
    password: {type: String, required: true },
    nickname: { type: String, default: 'User'},
    createdAt: { type: Date, default: Date.now }
});

Check if user is logged in:

function isLoggedIn(req, res, next) {
    if (req.isAuthenticated()) {
        return next();
    }
    req.session.oldUrl = req.url;
    res.redirect('/');
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This is how I solved it in a service that hosts stories. I had to display the number of users and their names on the current story page. I wanted to keep the solution simple enough so I decided to use a simple table in SQL.

In an SQL table with a single column, I stored PAGE_{PAGEID}_USER_{USERID}.

For every page when fetched by the user I added an entry on this table and queried the table column with the regex PAGE_{PAGEID}_USER_(.*) with updatedAt less than 1 minute of the current time.

This gives you the IDs of the users on the current page in the past 1 minute.

PS: The correct way to do this would be to do this very same thing in a Wide Column Store

over 4 years ago · Santiago Trujillo 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!