-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassportConfig.js
More file actions
37 lines (34 loc) · 1.1 KB
/
passportConfig.js
File metadata and controls
37 lines (34 loc) · 1.1 KB
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
const User = require('./user');
const bcrypt = require('bcryptjs');
const localStrategy = require('passport-local').Strategy;
module.exports = function(passport) {
passport.use(
new localStrategy(( username, password, done ) => {
User.findOne({ username: username }, ( err, user ) => {
if(err)
throw err;
if(!user)
return done(null, false);
bcrypt.compare(password, user.password, ( err, result ) => {
if(err) throw err;
if(result === true){
return done(null, user);
} else {
return done(null, false);
}
});
});
})
);
passport.serializeUser((user, cb) => {
cb(null, user.id)
});
passport.deserializeUser((id, cb) => {
User.findOne({ _id: id }, (err, user) => {
const userInformation = {
username: user.username,
};
cb(err, userInformation);
});
});
};