-
Notifications
You must be signed in to change notification settings - Fork 0
/
passport.js
35 lines (31 loc) · 1011 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
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const users = require('./usernames');
passport.serializeUser(function (user, done) {
// console.log('serialize');
done(null, user.id)
});
passport.deserializeUser(function (userId, done) {
// console.log('deserialize-passport');
done(null, users[userId])
});
const localStrategy = new LocalStrategy(
function (username, password, done) {
console.log('local strategy');
for (let i in users) {
if (users[i].username == username) {
if (users[i].password == password) {
users[i].id = i;
done(null, users[i])
} else {
done(null, false, {message: 'Wrong password'})
}
}
// else {
// done(null, false, {message: 'User not found'})
// }
}
}
);
passport.use(localStrategy);
module.exports = passport;