Easily protect your clients from session hijacking
npm install unique-session
$ npm install -S unique-session
`
#### 2. Integrate with your app
`js
const app = express();
const uniqueSession = require('unique-session');
// ...
app.use(uniqueSession());
// ... rest of routes and stuff ...
app.listen(process.env.PORT || 8080);
`
That's it.
#### Optional configuration
`js
const options = {
hashFields: ['accept', 'accept-language', 'user-agent'], // which keys to pick from request.headers
ipField: 'headers.x-forwarded-for', // the IP target path on your BE request
redirectTo: '/logout-reported' // where do redirect the user after malicious activity (default '/')
};
app.use(uniqueSession(options));
`
Debugging
In order to have visibility on what's going on in the background requests on the server, you can simply set the DEBUG environment variable to start seeing relevant logs fired from this package
You might want to see that all the relevant fields such as IP and headers are correctly passed for the hash signature. this could be easily achieved with -
`
$ DEBUG=unique-session* node app.js
``