Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function *(next) {
const authorization = this.get('Authorization');
if('' === authorization){
this.throw(401,'no token detected in http header \'Authorization\'');
}
const token = authorization.split(' ')[1];
let tokenContent;
try{
tokenContent = yield jwt.co_verify(token,config.jwt.cert);
}catch(err){
if('TokenExpiredError' === err.name){
this.throw(401,'token expired');
}
this.throw(401,'invalid token')
}
utils.print('ι΄ζιθΏ');
this.token = tokenContent;
return yield next;
};