javascript - JWT 令牌未定义
问题描述
在我尝试获取 JWT 令牌时,它总是说未定义。在邮递员中它的工作,但是当我通过客户端发送它给我一个错误。
const jwt=require('jsonwebtoken');
const config=require('config');
module.exports=function(req,res,next){
const token = req.body.token || req.query.token ||
req.headers['x-access-token']||req.header('x-auth-token');
if(!token){
res.status(401).send("not authorized user");
}
else {
try {
const decoded=jwt.verify(token,"my_secret");
req.userData=decoded;
next();
}catch(ex){
res.status(401).send("invalid token");
}
}
}
我在做什么错。如何在客户端获取此令牌并将其发送到服务器?
解决方案
推荐阅读
- php - Laravel dumpautoload url 格式错误
- javascript - 正则表达式替换字符串中不是数字或句点的任何内容
- amazon-ec2 - 如何将 statefulset 的数量迁移到 helm 图表
- ruby - 如何在远程服务器(由 pem 文件访问)rails 控制台上上传回形针图像?
- python - 获取具有特定上一个和下一个值的所有值
- javascript - 在多行字符串上使用八进制字符
- qt - Qt OpenGLWindow不渲染三角形
- ios - iOS:旋转后 UITextField 的 inputAccessoryView 没有更新
- php - 用 php 清除 mongoDB 集合,似乎不能永久工作
- solidity - 从另一个智能合约中读取可变大小的数据