code: function session() {
    return async function passportSession(ctx, next) {
      const req = ctx.req;
      let sessionUser;
      if (req._passport.session) {
        sessionUser = req._passport.session.user;
      }
  
      if (sessionUser || sessionUser === 0) {
        const user = await ctx.app.passport.deserializeUser(ctx, sessionUser);
        if (!user) {
          req._passport.session.user = undefined;
        } else {
          req[ctx.app.passport._userProperty] = user;
        }
      }
  
      return next();
    };
  }
docs: refactor passport session with koa middleware for performance https://github.com/jaredhanson/passport/blob/master/lib/strategies/session.js