Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

792
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!