Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix passport
  • Loading branch information
hoangvvo committed Jan 8, 2020
commit f4509c7a975c47c55da471fca5a02946acd955ac
6 changes: 3 additions & 3 deletions lib/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Strategy as LocalStrategy } from 'passport-local';
import { ObjectId } from 'mongodb';

passport.serializeUser((user, done) => {
done(null, user.id);
done(null, user._id);
});

// passport#160
Expand All @@ -14,11 +14,11 @@ passport.deserializeUser((id, req, done) => req.db
.then(user => done(null, user)));

passport.use(new LocalStrategy({ usernameField: 'email', passReqToCallback: true }, async (req, email, password, done) => {
const user = req.db
const user = await req.db
.collection('users')
.findOne({ email });
if (user && await bcrypt.compare(password, user.password)) done(null, user);
else done('Email or password is incorrect', user);
else done(null, false, { message: 'Email or password is incorrect' });
}));

export default passport;