const AuthHandler = require('../utils/auth'); module.exports = async (ctx, next) => { // 在这里进行鉴权逻辑,这里只是示例,您可以根据实际情况进行修改 const token = ctx.header.authorization; const authHandler = new AuthHandler(ctx); const auth = await authHandler.init(token); if(!auth){ ctx.status = 401; let err_essage = await authHandler.getError(); ctx.body = { message: err_essage }; return; }else{ ctx.state.user = await authHandler.getUser(); ctx.state.wmsuser = await authHandler.getWmsUser(); ctx.state.rules = await authHandler.getRuleList(); await next(); } };