我正在创建一个简单的辅助函数,它使用bcrypt
返回给定密码的哈希值。但每次我调用该函数时,它都会解析为 Promises { <pending> }
我做错了什么?
const saltPassword = async (password) => {
const newHash = await bcrypt.hash(password, saltRounds, (err, hash) => {
if (err) return err;
return hash;
});
return await newHash;
}
干杯
最佳答案
你应该做这样的事情
const saltPassword = async (password) => {
const newHash = await bcrypt.hash(password, saltRounds, (err, hash) => {
if (err) return err;
return hash;
});
return newHash; // no need to await here
}
// Usage
const pwd = await saltPassword;
关于javascript - 解决 Promise <pending>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46625005/