为了账号安全,请及时绑定邮箱和手机立即绑定

nodejs使用JWT进行token验证时,出现 UnauthorizedError,是什么原因?

nodejs使用JWT进行token验证时,出现 UnauthorizedError,是什么原因?

慕田峪7331174 2019-03-05 16:15:28
``if(token){    try{        let decoded = jwt.verify(token, config.jwt.secret);        //console.log(decoded)        let deadline = new Date()/1000;        if(decoded.exp <= deadline){            console.log('expired token');            ctx.redirect('/views/admin/login.html'); //token过期,则跳转到登陆页面        }else{            console.log('鉴权成功!');            await next();        }    }catch(err){        ctx.throw(401, 'expired token');      //token验证失败    }}else{    ctx.redirect('/views/admin/login.html');  //缺少token,则跳转到登陆页面}``上面代码,是如果存在token,则进行验证。我在验证时,可以获取token,也能正常解析,可是抛出UnauthorizedError错误,是为什么呢?
查看完整描述

1 回答

?
POPMUISE

TA贡献1765条经验 获得超5个赞

else{


        console.log('鉴权成功!');

        // 下面 这个中间是什么,应该是 next 报的错。

        await next();

}


查看完整回答
反对 回复 2019-03-19
  • 1 回答
  • 0 关注
  • 3748 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号