首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >登录用户错误(未处理的承诺错误) HTTP报头

登录用户错误(未处理的承诺错误) HTTP报头
EN

Stack Overflow用户
提问于 2022-07-22 18:25:31
回答 1查看 32关注 0票数 0

查找附加的我的代码试图以用户身份登录,它给了我http承诺标头错误(节点:17772) UnhandledPromiseRejectionWarning: error ERR_HTTP_HEADERS_SENT:无法在将标题发送给ServerResponse.header ServerResponse.setHeader (_http_outgoing.js:561:11)的客户端后设置

在(C:\Users\DELL\Desktop\codes\REACT-BLOG\blogbackend\node_modules\express\lib\response.js:170:12) ServerResponse.send

在(C:\Users\DELL\Desktop\codes\REACT-BLOG\blogbackend\node_modules\express\lib\response.js:267:15) ServerResponse.json

在C:\Users\DELL\Desktop\codes\REACT-BLOG\blogbackend\routes\auth.js:39:25 at processTicksAndRejections (内部/进程/任务队列),95:95:5(节点:17772),UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误起源于在异步函数中抛出而不带catch块,或者拒绝使用.catch()处理的承诺。若要在未处理的允诺拒绝时终止节点进程,请使用CLI标志--unhandled-rejections=strict (请参阅https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。(拒绝证: 2)。

下面是我的密码。

代码语言:javascript
运行
复制
router.post ("/login", async (req, res) => {
    try{
        const user = await User.findOne({ username: req.body.username });
        !user && res.status(400).json("wrong credentials!");

        const validated = await bcrypt.compare(req.body.password, user.password);
        !validated && res.status(400).json("wrong credentials!");

        const { password, ...others } = user._doc;
        res.status(200).json(others);
    } catch (err) {
        res.status(500).json(err);
    }
});
EN

Stack Overflow用户

发布于 2022-07-23 04:48:57

代码语言:javascript
运行
复制
router.post ("/login", async (req, res) => {
try{
    const user = await User.findOne({ username: req.body.username });
     return !user && res.status(400).json("wrong credentials!");

    const validated = await bcrypt.compare(req.body.password, user.password);
    return !validated && res.status(400).json("wrong credentials!");

    const { password, ...others } = user._doc;
    res.status(200).json(others);
} catch (err) {
    res.status(500).json(err);
}

});

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73084619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档