【发布时间】:2023-04-06 16:06:01
【问题描述】:
我想通过添加中间件“checkAuth”来保护我的路由。 此中间件检查 jwt 令牌的有效性。 我正在使用 Express 路由器。
但我不明白该怎么做。
我的 checkAuth 中间件:
module.exports = (req, res, next) => {
let token = req.headers.authorization.split(" ")[1];
try {
jwt.verify(token)
console.log("ok")
}catch (e) {
res.status(403)
}
next();
}
谢谢!
【问题讨论】:
-
console.log(e)在你的捕获中你得到了什么? -
console.log(e) 给了我“位置 17 处 JSON 中的意外标记”
标签: javascript node.js express jwt