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

793
Visualizações
ExpressJS and Redis - Can not set a session value because of invalid argument type error

I have a expressjs server and want to store the session in redis I have my session middleware which looks like the following:

//Importing required packages/files
const session = require('express-session');
const {v4: uuidv4} = require('uuid');

//Redis
const redisStore = require('connect-redis')(session);
const redis = require('redis');

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

redisClient.connect().then(() => console.log('Redis connected!'));

//Use Middleware
module.exports = (app) => {
    app.use(
        session({
            store: new redisStore({ client: redisClient }),
            secret: [process.env.SIGN_SESSION, process.env.VALIDATE_SESSION],
            name: 'sessionId',
            genid: function(req) {
                return uuidv4();
            },
            saveUninitialized: false,
            resave: false,
            cookie: {
                httpOnly: true,
                sameSite: true,
                secure: process.env.ENV === 'prod',
                signed: true
            }
        }),
    );
    console.log('Middleware loaded! (Session)');
};

It all seems to be working fine.. until I get to the login where I store the user object inside a session variable. Before I switched to redis I used to something like that

const userObj = {
    uid: apiResponse.message[0]._id,
    username: apiResponse.message[0].username
};

//Set user session object
req.session.user = userObj;

But now after I set the session store to Redis I am not able to set any session variables.. I always get the redis error TypeError: Invalid Argument Type. I already tried to stringify it with JSON or for testing only set the username.. but everytime I try to set a value it throws me an error.

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