I have a piec of code that looks like:
return user.isCorrectPassword(password, function(_err, same) {
assertExposable(same, 'login_fail');
const token = signToken(user);
console.log(token, 'TOKENN');
return token;
});
The token value in there is correct however I need that token from another piece of code. I realized that I would have to 'await' that code so I can get the token value however I am not sure whats the best way to convert that code to promises in order to do something like
const data = await ...
so data equals to token.
My attempt:
const foo = user.isCorrectPassword(password, function(_err, same) {
return new Promise((resolve, _reject) => {
assertExposable(same, 'login_fail');
const token = signToken(user);
resolve(token);
});
});