Skip to content

Instantly share code, notes, and snippets.

@CaptainYarb
Created February 27, 2014 20:29
Show Gist options
  • Save CaptainYarb/9258881 to your computer and use it in GitHub Desktop.
Save CaptainYarb/9258881 to your computer and use it in GitHub Desktop.
The real thing
// assume express and all that goodness (I actually am using Kraken)
// my middleware class
var userModel = function(userID){
return {
uid: userID,
logout: function(){
this.uid=false;
// how can I access req?
req.session.destroy(function(){
// TODO: handle callback
});
}
};
};
// extend req with my class
module.exports = function(){
return function(req,res,next){
req.user = new userModel(uid);
next();
}
}
// so essentially when I want to logout I simply use:
req.user.logout();
// how can user.logout access req?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment