Skip to content

Instantly share code, notes, and snippets.

@joepie91
Forked from anomaly44/Account.js
Last active February 6, 2017 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joepie91/d354a1cd1e62ba748d45 to your computer and use it in GitHub Desktop.
Save joepie91/d354a1cd1e62ba748d45 to your computer and use it in GitHub Desktop.
static login(email, password) {
return Promise.try(() => {
return Account.fetch(email))
}).then((acc) => {
return Promise.try(() => {
bcrypt.compareAsync(password, acc.password)
}).then(result => {
if (result) {
console.log(`User logged in: ${acc.email}`);
const token = jwt.sign(_.pick(acc, ['id', 'email', 'agencyId']),
process.env.JWT_SECRET, {expiresIn: 1440 * 60 * 11});
return {token};
} else {
throw new Error('Onjuist wachtwoord');
}
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment