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

268
Visualizações
Variable cannot access outside .then()

I am trying to set a authenticator for my local application. Found that I am not able to access my var outside my .then() method

var authenticated = false;
Auth.findtheUser({
}).then(user => {
  verified= user.name.verified;
  console.log("authenticated11", verified)
}
).catch(err => console.log(err));
console.log("authenticated", verified)

the output for authenticated11 output comes as true but not the one at the end Could anyone help me out on this. New to javascript.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You cant use the result of an asynchronous function directly after it in JS. See this question: How to return the response from an asynchronous call

about 4 years ago · Juan Pablo Isaza Relatório

0

According to what you described in a comment in this answer. You are facing an exception related to the scope.

var authenticated = false;
Auth.findtheUser({
  }).then(user => {
    verified= user.name.verified;
    console.log("authenticated11", verified)
}
).catch(err => console.log(err));
// This will throw an exception because verified does not exist in this scope
console.log("authenticated", verified)

You should change that to this

var authenticated = false;
var verified;
Auth.findtheUser({
  }).then(user => {
    verified= user.name.verified;
    console.log("authenticated11", verified)
}
).catch(err => console.log(err));
// This will throw an exception because verified does not exist in this scope
console.log("authenticated", verified)
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