Skip to content

Instantly share code, notes, and snippets.

@benbarnett
Created October 15, 2013 11:28
Show Gist options
  • Save benbarnett/6990163 to your computer and use it in GitHub Desktop.
Save benbarnett/6990163 to your computer and use it in GitHub Desktop.
NodeJS Signed cookies
/**
* Signed session cookies used for persistence
* @param {[type]} name [description]
* @return {[type]} [description]
*/
module.exports = function(name) {
return function(req, res, next) {
req.session = req.signedCookies[name] || {};
res.on('header', function() {
res.cookie(name, req.session, { signed: true });
});
next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment