yapi/server/middleware/checkToken.js
2017-07-27 19:49:26 +08:00

18 lines
574 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// const jwt = require('jsonwebtoken');
//检查token是否过期
module.exports = async ( ctx, next ) => {
// const authorization = ctx.get('Authorization');
// if (authorization === '') {
// ctx.throw(401, 'no token detected in http header ');
// }
// const token = authorization.split(' ')[1];
// let tokenContent;
// try {
// tokenContent = await jwt.verify(token, 'qunar'); //如果token过期或验证失败将抛出错误
// } catch (err) {
// ctx.throw(401, 'invalid token');
// }
await next();
};