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

107
Vistas
Next js session version 4 with middleware client side

I'm using next js session v4.0.4 client side with middleware and i wanna know how to store user credential in the session in login page my middleware.js :

import { NextRequest, NextResponse } from 'next/server'
import session from 'next-session'

export async function middleware(req, res) {
  await session()(req, res)
  return NextResponse.next()
}

my session.js

import nextSession from 'next-session'


export const getSession = nextSession()
function withSession(handler) {
  return async function handlerWithSession(req, res) {
    await getSession(req, res)
    return handler(req, res)
  }
}

function applySessionOptions(req, res) {
  return getSession(req, res)
}

function withSessionOptions(handler) {
  return withSession(handler)
}

export { applySessionOptions as applySession }
export { withSessionOptions as withSession }

My login service

import { withSession} from './session'
const handler = async (req, res) => {
 try {
        req.session.logged = true,
        req.session.commit();
  
  } catch (error) {
    console.log(error)
  }
}
export default withSession(handler)

When i do console.log(req.session) in my login page i find the logged value but when i try to access from another service the req.session i don't find the logged value any help please

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