-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.js
33 lines (25 loc) · 863 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
var passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
User = require('./schemas/user');
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({'username': username}, function(err, user) {
if(err) return done(err);
if(!user) return done(null, false);
if(user.password != password) {
return done(null, false);
}
return done(null, user);
});
}
));
// These functions must be defined in order to store the user information in the session.
passport.serializeUser(function(user, done) {
done(null, user._id, user.type);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});
module.exports = passport;