forked from jmcooper/ng2f-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
passport.js
40 lines (34 loc) · 864 Bytes
/
passport.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
var passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
users = require('./database/users');
module.exports = function() {
passport.use(new LocalStrategy(
function(username, password, done) {
var found = users.find(user => {
return user.userName.toLowerCase() === username;
})
if(found) {
return done(null, found);
} else {
return done(null, false);
}
}
));
passport.serializeUser(function(user, done) {
// console.log(5, user);
if(user) {
done(null, user.id);
}
});
passport.deserializeUser(function(id, done) {
// console.log(3, id);
var found = users.find(user => {
return user.id === id;
})
if(found) {
return done(null, found);
} else {
return done(null, false);
}
})
}