-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
45 lines (37 loc) · 1.05 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
var redsess = require('redsess');
function Redission (routes, cookiename, cookieexpire, redisclient, keys) {
this.routes = routes;
this.cookiename = cookiename;
this.cookieexpire = cookieexpire;
this.redisclient = redisclient;
this.keys = keys;
this.redSession = function redSession (req, res, cb) {
var entrypoint = req.url.split('/')[1];
if(routes.indexOf(entrypoint) > -1) {
var session = new redsess(req, res, {
cookieName: cookiename,
expire: cookieexpire,
client: redisclient,
keys: [keys] // this becomes a keygrip obj
});
req.session = session;
res.session = session;
req.session.get('auth', function (err, auth) {
if(err) throw err; // This should catch errors in the future
if(!auth && routes.indexOf(entrypoint) > -1) {
req.session.legit = false;
cb();
}
else {
req.session.legit = true;
cb();
}
});
}
else {
cb();
}
};
}
module.exports = Redission;