对Node.js开发人员来说更新鲜 但是授权承载的时间有误 我发布了一些代码和代码的屏幕截图 请帮助我解决错误
router / user.js Here i pass auth middleware, and writen code in middleware/awth.js
router.get('/users', auth, async (req,res) => {
try{
const user = await User.find({})
res.send(user)
}catch(e){
res.status(500).send()
}
})
中间件/auth.js Here i print token value in terminal but error occure
const jwt = require('jsonwebtoken')
const User = require('../models/user')
const auth = async (req, res, next) => {
try{
const token = req.header('Authorization')
console.log(token)
} catch(e) {
res.status(401).send({ error: 'Please authenticate.' })
}
}
module.exports = auth
*在邮递员中,我使用电子邮件和密码登录,它生成令牌*
**我将该令牌粘贴到标题中的键和值对中** In key i written Authorization and in value i written Bearer space token value and send but not prceed any and not shwoing any token value in terminal
Thsis is showing after click send ...error occure
,我使用最新版本的邮递员7+ 请帮助我解决我的错误