灏天阁

Node/Koa2[43]: 退出登录

· Yin灏

路由层

src/routes/api/user.js

//...
const { logout } = require("../../controller/user");
//...
const { loginCheck } = require("../../middlewares/loginChecks");

router.post("/logout", loginCheck, async (ctx, next) => {
  ctx.body = await logout(ctx);
});
//...

controller 层处理

src/controller/user.js

//..
const { SuccessModel } = require("../model/ResModel");
//...
async function logout(ctx) {
  delete ctx.session.userInfo;
  return new SuccessModel();
}

module.exports = {
  //...
  logout,
};

- Book Lists -