Skip to content

Instantly share code, notes, and snippets.

@fmarier
Created April 30, 2012 23:23
Show Gist options
  • Save fmarier/2563607 to your computer and use it in GitHub Desktop.
Save fmarier/2563607 to your computer and use it in GitHub Desktop.
Sample code demonstrating a node-client-sessions bug (issue 14)
#!/usr/bin/env node
const
express = require('express'),
app = express.createServer(),
clientSessions = require("client-sessions");
app.use(clientSessions({
secret: 'secret',
cookie: {
path: '/api'
}
}));
app.get(
'/', function (req, res){
res.send('I haven\'t done anything!');
});
app.get(
'/foo', function (req, res){
res.send('req.session.foo = ' + req.session.foo);
});
app.get(
'/api/foo', function (req, res){
res.send('[API] req.session.foo = ' + req.session.foo);
});
app.get(
'/api/login', function (req, res){
req.session.foo = 'DEFINED!';
console.log('foo has been set');
res.redirect('/api/foo');
});
app.get(
'/api/logout', function (req, res) {
req.session.reset(['csrf']);
console.log('session has been reset');
res.redirect('/api/foo');
});
app.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment