I\xe2\x80\x99m 尝试将承载令牌添加到我的 POST 路由中。当我通过 Postman 提交 POST 请求时,我\xe2\x80\x99m 得到以下输出:
\n\n{\n "success": true,\n "token": "Bearer undefined"\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的 user.js 代码:
\n\nrouter.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)