-
-
Save joepie91/d354a1cd1e62ba748d45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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