Skip to content

Instantly share code, notes, and snippets.

@AndrejGajdos
Last active June 24, 2018 07:38
Show Gist options
  • Save AndrejGajdos/e3e57a16ed18e3f3ead0a3ea8e3a5a29 to your computer and use it in GitHub Desktop.
Save AndrejGajdos/e3e57a16ed18e3f3ead0a3ea8e3a5a29 to your computer and use it in GitHub Desktop.
passport.use(
new LocalStrategy(
{
usernameField: 'email',
passwordField: 'password',
},
async (email, password, done) => {
let user = null;
await getAsync('usersMockDatabase').then((users) => {
const currUsers = JSON.parse(users);
user = currUsers.find(currUser => currUser.email === email);
});
if (!user) {
done({ type: 'email', message: 'No such user found' }, false);
return;
}
if (bcrypt.compareSync(password, user.password)) {
done(null, { id: user.id, email: user.email, userName: user.userName });
} else {
done({ type: 'password', message: 'Passwords did not match' }, false);
}
},
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment