2022-01-04 服务端登录校验(assert)
后端 routes.js
const assert = require('http-assert')
// 资源列表
router.get('/', async (req, res, next) => {
const token = String(req.headers.authorization || '').split(' ').pop()
assert(token, 401, '请先登录')
const { id } = jwt.verify(token, app.get('secret'))
assert(id, 401, '请先登录')
req.user = await AdminUser.findById(id)
assert(req.user, 401, '请先登录')
await next()
}, async (req, res) => {})
app.post('/admi
共有 0 条评论