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

137
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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