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

130
Vistas
Issue reading req.session.customProperty (express-session) from within express middleware

I have an issue with not being able to access a custom variable I set to the session object when a user logs into my service.

Post request from front-end

const sendChat = async (contents, cid, agentID) => {
  const config = {
    headers: {
      "Content-Type": "application/json",
    },
    withCredentials: true,
  };

  const body = JSON.stringify({
    channelID: cid,
    message: contents,
    agentID: agentID,
  });

  console.log(`AgentID: ${agentID}`);

  return await axios.post(
    "http://localhost:5000/api/chat/sendMessage/",
    body,
    config
  );
};

Session configuration in server

app.use(
  session({
    secret: config.get("sessionSecret"),
    name: "sid",
    cookie: { maxAge: 990000, httpOnly: false },
    resave: true,
    store: MongoStore.create({ mongoUrl: config.get("mongoURI") }),
    saveUninitialized: false,
  })
);

In both cases when I login to the service, through POSTMAN or with axios in the front-end, it creates a session containing the userID field that I can see when I check my store (mongoDB). However, when I get a request from axios, req.session.userID is undefined when try to access it in a route -- whereas with postman, it is defined when I try to access it in the route. I have cors enabled in the server.

const corsOptions = {
  origin: "http://localhost:3000",
  credentials: true,
  optionSuccessStatus: 200,
};

app.use(cors(corsOptions));

Why does it work with POSTMAN but not through the front-end localhost?

EDIT: I made a logical error in my front-end, I had added the withCredentials: true property to the wrong request.

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