简体   繁体   English

bcrypt 没有返回任何东西

[英]bcrypt is not returning anything NODEJS

THIS ALWAYS USED TO WORK, somehow this is not working for me:这总是有用的,不知何故这对我不起作用:

The thing that I am using to compare the password:我用来比较密码的东西:

router.post("/login", [
    check('email', 'Email is required').isEmail(),
    check('password', 'Password is required').not().isEmpty()
    ], async (req, res) => {
    const { email, password } = req.body;
    const errors = validationResult(req);
    if ( !errors.isEmpty() || !email || !password ) {
        return res.status(401).json({err: "Authentication failure"});
    };
    try {
        const user = User.findOne({ email: email });
        if(!user) {
            return res.status(401).json({err: "Invalid username or password"});
        }
        const isValid = await bcrypt.compare(password, user.password);  //// <-------HERE!!!!!
        console.log("Not reaching here")
        if (!isValidPassword) {
            return res.status(401).json({err: "Invalid username or password"});
        }
        //if valid password 
        res.status(200).send("SUCCESS");
    } catch (error) {
        res.status(500).json({err: "Internal server error"});
    }
})

Can someone help me out?有人可以帮我吗? This is the first time I'm stuck here.这是我第一次被困在这里。 Thanks in advance.提前致谢。

I was not using "await" while making a DB query: correction:我在进行数据库查询时没有使用“等待”:更正:

const user = await User.findOne({ email: email });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM