Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

337
Vistas
In next.js, how to implement session?

I have some experience of python flask and django, now I'm learning next.js development, and struggling to figure out how to implement session.

My project is using koa as the web server and next.js as one middleware, code like this

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);
});

In the above code, ctx.session carries the session data for each request, but the problem is I don't know how to pass the session data to next.js, because the next.js entry function call handle(ctx.req, ctx.res) doesn't take extra session data as arguments.

Then I look at next-auth, which also provide session functionalities, and I'm really deeply confused, which one to use and why?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda