Wednesday, 31 May 2017

How to add current logged in status to Users Schema in MongoDB using Passport and node.js

I’m quite new to backend development…

With using my API I would like to be able to display a list of users and also indicate if they are currently logged in. I got the basic authentification working using passport and json web token I’m not looking to get the current logged in user. I want to be able to retrieve a list of users and see if they are logged in or not.

Like this:

var users = Users.find({});
// console.log(users) output:
{
  name: 'foo'
  password: ...
  isLoggedIn: false
},
{
  name: 'bar'
  password: ...
  isLoggedIn: true
},
{
  name: 'baz'
  password: ...
  isLoggedIn: false
}

isLoggedIn would be set to true if the user is currently logged in and to falseif not.

How can I do that? Thank you!



via chitzui

No comments:

Post a Comment