Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
Redis sessions not persisting throughout different requests in express

I have 2 routes on the backend of my app. The first one sets a session using redis and using a different route i try to retrieve the session that was saved prior. However, when trying to retrieve the session, i get a different one from the one i created.

this is how i create a session and assign a property to it:

app.post("/login", (req, res) => {
req.session.userId = 1
});

and this is how i try to retrieve it:

app.get("/cookie", (req, res) => {
res.json(req.session);
});

But when the req.session of the get request is logged, I get one without the property userID. Even though, i am able to view the key and value of the session using the redis-client with the keys and mget command.

this is how the cookie and session is configured

app.use(
session({
  name: "cookie",
  store: new RedisStore({ client: redisClient }),
  secret: "xxxxx",
  resave: false,
  saveUninitialized: false,
  cookie: {
    secure: false,
    httpOnly: false,
    maxAge: 1000 * 60 * 10,
  },
})
);

and this is the redisClient:

const redisClient = redis.createClient({
host: "localhost",
port: 6379,
});

How do I properly retrieve the session that i set on the post request? Am I using redis entirely wrong or am i just missing something?

Thanks!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda