Introduction:
Ok, I put together a good application that allows users to log in (node.js, passportjs, mongodb). Now, while promoting the application, I need to find out who is logged in.
Theory:
So this idea just hit me, I think the best idea would be to transfer connected = trueor connected = falsewhen the user logs in and logs out of the user.
Question:
My question is, what is the best way to track which sessions are active / connected / registered in my application? Will this be conveyed in these model properties?
Is there a standard way to track sessions for all users? I do not want this to be a stubborn question that is against the rules, but there must be a technical way to keep track of sessions! What would be best for this?
Tests:
So, I can be more specific, I put it to the test, and I forgot inside my handlebars template. I can only access the properties of this mongodb user model.
<div class="row">
{{#if user.connected}}
{{#each user.connected}}
<li>{{this}}</li>
{{/each}}
{{/if}}
</div>
The above obviously does not work because the data is transmitted when the route for this page is completed.
res.render('profile', { user : req.user });
So, I stick connected: true, connected: falseit’s easy, it works and makes sense to me.
Clarified Question:
, , , handlebars. admin = true, .
, . , , mongoDB? , -
AppUser.find({ connected: true }, function (err, user) {
console.log(user);
res.render('profile', { user : user });
});
- , . , , "res.render", ?
: , , , .
, res.render('chat', { user : req.user }), , req.user . , .
AppUser.find({}, function (err, users) {
console.log(users);
res.render('profile', { user: req.user, users : users });
});
<div class="row">
{{#each users}}
{{#if this.connected}}
<li><b>Connected:</b> {{this.connected}}</li>
{{#if this.facebook.email}}
<li><b>Email:</b> {{this.facebook.email}}</li>
{{else}}
<li><b>Email:</b> {{this.local.email}}</li>
{{/if}}
{{/if}}
{{/each}}
</div>
^^^ !:) ?