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

139
Views
Cannot read property of 'watchlist' undefined
 authenticate(request, response) {
    const user = userstore.getUserByEmail(request.body.email);
    if (user) {
      response.cookie('watchlist', user.email);
      logger.info('logging in' + user.email);
      response.redirect('/start');
    } else {
      response.redirect('/login');
    }
  },

 getCurrentUser (request) {
  const userEmail = request.cookies.watchlist;
  return userstore.getUserByEmail(userEmail);
  }
} 

Here the code authenticates a user and up above it defines 'watchlist' as a cookie, however it keeps telling me it is undefined. How do I fix this?

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

0

getUserByEmail is probably an async function. Be sure use await to make sure that we wait for the promise to resolve and return a value before moving to the next line. In your case it will look like this:

 async authenticate(request, response) {
    const user = await userstore.getUserByEmail(request.body.email);
    if (user) {
      response.cookie('watchlist', user.email);
      logger.info('logging in' + user.email);
      response.redirect('/start');
    } else {
      response.redirect('/login');
    }
  },

 async getCurrentUser (request) {
  const userEmail = request.cookies.watchlist;
  return await userstore.getUserByEmail(userEmail);
  }
} 

Further reading: JavaScript Async Await

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!