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

794
Vistas
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 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