-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth.js
40 lines (26 loc) · 892 Bytes
/
auth.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
const passport = require('passport');
const session = require('express-session');
const LocalStrategy = require('passport-local');
var MemoryStore = require('memorystore')(session);
//const bcrypt = require('bcrypt');
module.exports = function(app, db) {
app.use(session({
secret: 'SacredCow',
resave: true,
saveUninitialized: true,
store: new MemoryStore({
checkPeriod: 86400000}),
}
));
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser((id, done) => {
db.query('SELECT * FROM users WHERE id = (?)', id, function(err, doc, fields) {
if (err) {return console.log('Error to deserializeUser: ' + err);}
done(null, doc);
});
});
}