``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錯誤,是為什么呢?
nodejs使用JWT進行token驗證時,出現 UnauthorizedError,是什么原因?
慕田峪7331174
2019-03-05 16:15:28