Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda