Skip to content
关注公众号,获取新课通知

权限验证


中间件:app/middleware/admin_auth.js

js
module.exports = (option, app) => {
  return async (ctx, next) => {
    if (!ctx.session.auth) {
      ctx.toast("请先登录", "danger");
      return ctx.redirect(`/admin/login`);
    }
    await next();

    if (ctx.status === 404) {
      await ctx.pageFail("页面不存在");
    }
  };
};

配置:config/config.default.js

js
config.middleware = [
  // ...
  "adminAuth",
  // ...
];
config.adminAuth = {
  ignore: [
    "/api",
    "/admin/login",
    "/admin/loginevent",
  ],
};