Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
How to pass koa-session data to page components in NextJS?

In my NextJS project, I created a custom server with koa + koa-session, so that I can have some session data per each request, like the code below,


import next from "next";
import Koa from "koa";
import Session from "koa-session";
import Router from "koa-router";

...
const next_app = next({...});
const handle = next_app.getRequestHandler();

next_app.prepare().then(async () => {
  const server = new Koa();
  const router = new Router();
  server.use(Session(server));  // use koa-session middleware
  ...
  router.get("(.*)", async (ctx) => {
    console.log("server.js session: ", ctx.session);
    ...
    // create or update session data
    ctx.session.custom_data += 123;
    
    // but how to pass ctx.session to handle(), then to page components?
    await handle(ctx.req, ctx.res);
});

As said in the comment, how to pass ctx.session data to page components?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!