Tuesday, 4 April 2017

Passport.js remember on server which users are online/logged in

I use passport.js on an Node.js Express Server with MongoDB for Authentification and Authorization. For the communication between nodejs and and mongodb i use mongoose and passport-local-mongoose modules.

Now my problem is that I have no clue where I can manipulate the code to update the users database entry when logging in and logging out because the serializeUser and deserializeUser functions come directly out of the passport-local-mongoose module.

Passport Configuration

var Account = require('./models/account');    
passport.use(new LocalStrategy(Account.authenticate()));
passport.serializeUser(Account.serializeUser());
passport.deserializeUser(Account.deserializeUser());

Account model

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var passportLocalMongoose = require('passport-local-mongoose');

var Account = new Schema({
    username: String,
    password: String,
    //Other user 'properties'...
    online: Boolean
});

//This line assigns the serialize and deserialize Funktions to the model Account
Account.plugin(passportLocalMongoose);

module.exports = mongoose.model('Account', Account);

Please give me some ideas! Thanks in advance!



via rapgru

No comments:

Post a Comment