在写vue+nodejs项目的校验token时,出现了这个错误
Error: Bad "options.expiresIn" option the payload already has an "exp" property.
at Object.module.exports [as sign] (D:\study\myproject1\nodejs\myapp\node_modules\jsonwebtoken\sign.js:133:20)
at Object.generate (D:\study\myproject1\nodejs\myapp\util\jwt.js:8:25)
at D:\study\myproject1\nodejs\myapp\index.js:47:34
at Layer.handle [as handle_request] (D:\study\myproject1\nodejs\myapp\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (D:\study\myproject1\nodejs\myapp\node_modules\express\lib\router\index.js:317:13)
at D:\study\myproject1\nodejs\myapp\node_modules\express\lib\router\index.js:284:7
at Function.process_params (D:\study\myproject1\nodejs\myapp\node_modules\express\lib\router\index.js:335:12)
at next (D:\study\myproject1\nodejs\myapp\node_modules\express\lib\router\index.js:275:10)
at next (D:\study\myproject1\nodejs\myapp\node_modules\express\lib\router\route.js:127:14)
at next (D:\study\myproject1\nodejs\myapp\node_modules\express\lib\router\route.js:131:14)
习惯性的找上csdn找百度,结果都没有找到解决办法,最后看了一下,发现是因为jwt.sign的第一参数内存在iat和exp两个属性时就会报错
{
id: 1,
username: 'qw123',
password: '123456',
phone: '18379131312',
iat: 1672139741,
exp: 1672143341
}
解决办法:如果你传入的对象中有iat和exp两个属性,删掉他们就行了,如:delete payload.iat,delete payload.exp