【发布时间】:2020-02-24 05:42:22
【问题描述】:
我试图像这样使用 bcrypt。
var token = bcrypt.hash(info, 10, function (err, hash) {
if (err) return null;
return hash;
});
//pass the info param to token whenever I call token
token("test");
如果可以,有人可以向我解释一下,如果可以,这是一个好习惯吗?
我基本上想这样做,因为出于某种原因,req.session.destroy 并没有真正从 Firefox 中删除会话,但它适用于 chrome。
【问题讨论】:
-
不确定 bcrypt 包和散列函数,但 javascript 是绝对异步的,它会将内部函数发送到以太,并继续它的快乐方式。
-
我今天遇到了类似的问题。在常规函数中,我需要调用一个 Promise 函数并返回它的值,例如
const x = Promise.resolve(1); const y= ()=>{//here I can't use await because then I'd have to make y into async and I can use .then() because I wouldn't be able to return the value of x}关于如何继续的任何建议?
标签: javascript function return bcrypt