23 lines
558 B
JavaScript
23 lines
558 B
JavaScript
module.exports = (options) => {
|
|
let param = Object.assign({}, {
|
|
minRole: 6,
|
|
status: ['2']
|
|
}, options)
|
|
|
|
return async function auth(ctx, next) {
|
|
try {
|
|
console.log(ctx.state)
|
|
if (!ctx.state.user.role && param.minRole >= ctx.state.user.role) {
|
|
throw '没有权限'
|
|
}
|
|
if (Array.isArray(param.status) && param.status.indexOf(ctx.state.user.status) < 0) throw '用户状态错误';
|
|
} catch (error) {
|
|
return ctx.body = {
|
|
code: 40000,
|
|
message: error
|
|
};
|
|
}
|
|
await next();
|
|
};
|
|
};
|