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

184
Views
JS - cannot set property of undefined

My code:

module.exports = async (req, res, next) => {

    const redirectURL = ((req.originalUrl.includes("login") || req.originalUrl === "/") ? "/selector" : req.originalUrl);
    
    if(req.session.user){
        return next();
    } else {
        const state = Math.random().toString(36).substring(5);
        req.client.states[state] = redirectURL;
        return res.redirect(`/api/login?state=${state}`);
    }
};

Give me this error:

Cannot set properties of undefined (setting 'yhgrz0jg')

Can anyone help me I've tried everything and I can't solve it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

req.client.states is undefined, that's why you're getting error. Why are you setting it anyway, since you're not using that value anywhere later on?

about 4 years ago · Juan Pablo Isaza Report
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!