小编Imp*_* 14的帖子

不记名令牌未定义

I\xe2\x80\x99m 尝试将承载令牌添加到我的 POST 路由中。当我通过 Postman 提交 POST 请求时,我\xe2\x80\x99m 得到以下输出:

\n\n
{\n    "success": true,\n    "token": "Bearer undefined"\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我的 user.js 代码:

\n\n
router.post("/login", (req, res) => {\n  const email = req.body.email;\n  const password = req.body.password;\n\n  //find user by email\n  User.findOne({ email }).then(user => {\n    //check for user\n    if (!user) {\n      return res.status(404).json({ email: "user not found" });\n    }\n    //check password\n    bcrypt.compare(password, user.password).then(isMatch => {\n      if (isMatch) {\n        //user matched\n        const payload = { id: user.id, name: user.name, avatar: user.avatar }; //create …
Run Code Online (Sandbox Code Playgroud)

node.js express jwt bearer-token

0
推荐指数
1
解决办法
5830
查看次数

标签 统计

bearer-token ×1

express ×1

jwt ×1

node.js ×1