How to use the jsonwebtoken.co_verify function in jsonwebtoken

To help you get started, we’ve selected a few jsonwebtoken examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Ma63d / kov-blog / server / middlewares / verify_token.js View on Github external
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;
};