const validateLoginInput = async (data) => {
let errors = {};
//check if user is blocked or not in redis cache
await redisClient.select(2, (err) => {
console.log('b');
if (err) {
console.log('c');
errors.authFailedMessage = 'Server connection failed. Try again';
} else {
console.log('d');
redisClient.get(`${data.userEmailLowerCase}`, (err, replay) => {
if (err) {
console.log('e');
errors.authFailedMessage = 'Server connection failed. Try again';
} else if (replay === 'Blocked') {
console.log('f');
errors.authFailedMessage =
'You are temporary blocked. Try again in an hour.';
}
});
}
});
return {
errors,
isValid: isEmpty(errors),
};
};
module.exports = validateLoginInput;
我正在创建阻止电子邮件的列表。我知道问题是,在“return”被执行之前,承诺返回值的时间太迟了。但是,我试着用
new Promise(resolve, reject) or .then()
两个都不起作用。然后()返回redisclient()不是函数。而且,我认为async/await将等待承诺返回。它似乎适用于其他东西,但当我在redisclient上使用它时就不起作用了。
暂无答案!
目前还没有任何答案,快来回答吧!