簡體   English   中英

bcrypt 沒有返回任何東西

[英]bcrypt is not returning anything NODEJS

這總是有用的,不知何故這對我不起作用:

我用來比較密碼的東西:

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"});
    }
})

有人可以幫我嗎? 這是我第一次被困在這里。 提前致謝。

我在進行數據庫查詢時沒有使用“等待”:更正:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM