我想通过添加中间件“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();
}
哈士奇WWW
慕少森
相关分类